Skip to content

Image width and height #187

Open

Description

@gmchaturvedi1

First of all thanks for the awesome lib.I am facing a issue ,i am getting image buffer and i am able to show if i fix height and width in img element. But can u please help to identify the exact image width and height so it will come as it is.

Thanks & Reagrds
gmchatrvedi

Activity

  1. gmchaturvedi1 commented on Feb 13, 2019

    @gmchaturvedi1
    Author

    please suggest if any other way @mwilliamson to solve this

  2. gmchaturvedi1 commented on Apr 18, 2019

    @gmchaturvedi1
    Author

    Hi Please suggest if any update . Or suggest any way if i can achieve this

  3. jaydevvaghela943 commented on May 11, 2021

    @jaydevvaghela943

    Hi Friends,

    We can set image width and height by image option. But it apply on all image.
    image

  4. vijayis commented on Mar 15, 2023

    @vijayis

    Hi williamson,
    I am using your mammoth plugin for docx to html conversion, everything is fine but I am not able retain the width and height of the image kindly suggest any method for this.
    Thank You.

  5. kennylbj commented on Apr 7, 2023

    @kennylbj

    This code is working:

    mammoth.convertToHtml(
                { arrayBuffer },
                {
                  convertImage: mammoth.images.imgElement((image) => {
                    return image.read('base64').then((imageBuffer) => {
                      return {
                        src: 'data:' + image.contentType + ';base64,' + imageBuffer,
                        style: 'max-width: 100%',
                      };
                    });
                  }),
                },
              );
  6. jan-schweiger commented on Jun 14, 2024

    @jan-schweiger

    Hi @mwilliamson,

    do you maybe have any updates on this? This is the last missing requirement for us to test your library in production.

    It would be great to get the size (width and height) that images have within the Word file.

    const options = {
      convertImage: mammoth.images.imgElement(async image => {
        return {
          src: // ...
          width: image.width + "mm",  // <-- get image width (maybe as px, pt or mm meisure unit)
          height: image.height + "mm"  // <-- get image height (maybe as px, pt or mm meisure unit)
        };
      })
    }
    

    I have attached a Word file, where I added an image that I resized.

    Image Test.docx

  7. mwilliamson commented on Jun 15, 2024

    @mwilliamson
    Owner

    No particular updates, and I've just finished my week off work so I have no idea when I'll have time to look at this, I'm afraid.

  8. jan-schweiger commented on Jun 15, 2024

    @jan-schweiger

    Thank you for your quick reply again @mwilliamson. Hopefully a solution is possible in the near future.

  9. kettanaito commented on May 26, 2025

    @kettanaito

    This should be a matter of parsing wp:extent or pic:spPr.a:xfrm.a:ext and grabbing its cx and cy for image width and height, respectively.

    Just note that DOCX doesn't preserve the original image dimensions. We can get them from the image buffer, but it depends how Mammoth works (I'm just learning the ropes). I would love to have the resized image dimensions exposed from the parser. If I can figure out this package, I will open a pull request.

  10. rosenbauerwillbacker commented on May 26, 2025

    @rosenbauerwillbacker

    A solution would be really great. Any updates on this one @mwilliamson?

  11. mwilliamson commented on May 26, 2025

    @mwilliamson
    Owner

    Nope, no updates.

  12. kettanaito commented on May 27, 2025

    @kettanaito

    Opened an extremely rough pull request at #445. Would appreciate some guidance and discussion around the implementation in there, @mwilliamson. I see your PR description says new PRs are generally not accepted. I hope we can still discuss and ship this together. I would appreciate your help a ton!

  13. mariatahler commented on May 27, 2025

    @mariatahler

    This would be a great addition to Mammoth. Would it be possible to accept this PR?

  14. kettanaito commented on May 27, 2025

    @kettanaito

    Note that this pull request still needs some work to be done before it can be merged. I would appreciate if we gave Michael enough time to look into this and don't bump this issue until then. You can also sponsor his work because it's extremely time-consuming to be maintaining a widely-used project. Thanks.

  15. jan-schweiger commented on May 27, 2025

    @jan-schweiger

    Thanks for the info @kettanaito, I can imagine. Thanks for the link, I (or my start-up) will donate some money this week.

  16. mwilliamson commented on May 28, 2025

    @mwilliamson
    Owner

    Opened an extremely rough pull request at #445. Would appreciate some guidance and discussion around the implementation in there, @mwilliamson. I see your PR description says new PRs are generally not accepted. I hope we can still discuss and ship this together. I would appreciate your help a ton!

    I'm afraid I'm still not accepting pull requests, although if you have minimal example documents from the sources you mentioned (Microsoft, Google Docs, Apple Pages), then they would be helpful to include in this issue.

  17. kettanaito commented on May 28, 2025

    @kettanaito

    What will be the best way to share them here?

    Also, I'm new joining to the project, is there anywhere I can read about your stance of not accepting PRs? What does that mean for the project's development? Is this an actively maintained project?

    I am in a dire need of a good DOCX parser. I've written one myself and it does 90% of what I need but that 10% is tricky. Mammoth nails those 10% well (but has some gaps in other areas, image dimensions being one of them). Waiting isn't part of my development culture so I'd like to know how much I can rely on this library! Thanks.

  18. mwilliamson commented on May 28, 2025

    @mwilliamson
    Owner

    What will be the best way to share them here?

    You should be able to upload the files as part of a comment.

    Also, I'm new joining to the project, is there anywhere I can read about your stance of not accepting PRs?

    It's generally more work to accept pull requests, especially given there are multiple implementations, than it is just to do the work myself.

    What does that mean for the project's development?

    It means the project is dependent on when I get the time and motivation to work on it, which is not much in the last few years.

    Is this an actively maintained project?

    It's actively maintained in that I'll try to address bugs and occasionally add support where it seems useful and in keeping with the philosophy of the project, but I wouldn't expect any significant additions at this point.

    I am in a dire need of a good DOCX parser. I've written one myself and it does 90% of what I need but that 10% is tricky. Mammoth nails those 10% well (but has some gaps in other areas, image dimensions being one of them). Waiting isn't part of my development culture so I'd like to know how much I can rely on this library! Thanks.

    If waiting isn't part of your development culture, and Mammoth doesn't already broadly cover what you need, then I'd suggest you shouldn't rely on this library.

  19. kettanaito commented on May 29, 2025

    @kettanaito

    Really appreciate the response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions