insert image -> inserted image resized

3,067 views
Skip to first unread message

hemso...@gmail.com

unread,
Jun 10, 2015, 4:32:51 AM6/10/15
to openpyx...@googlegroups.com
I add a picture in the size 600x70 XLSX file
open the document in the editor -> Image size 580x70

how to fix it?

Charlie Clark

unread,
Jun 10, 2015, 4:47:48 AM6/10/15
to openpyx...@googlegroups.com
Am .06.2015, 10:32 Uhr, schrieb <hemso...@gmail.com>:

> I add a picture in the size 600x70 XLSX file
> open the document in the editor -> Image size 580x70

I'm not sure I really understand the problem. Image support in openpyxl
certainly isn't brilliant but I don't think it changes the aspect ratio of
an image. Can you provide a sample image and file?

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226

hemso...@gmail.com

unread,
Jun 10, 2015, 5:02:15 AM6/10/15
to openpyx...@googlegroups.com
the attachment waybill (Russian)
in the waybill image with a bar code. Original Size: 600x700
in document: ~580x70

среда, 10 июня 2015 г., 11:47:48 UTC+3 пользователь Charlie Clark написал:
НТ00529030.xlsx

Charlie Clark

unread,
Jun 10, 2015, 5:39:34 AM6/10/15
to openpyx...@googlegroups.com
Am .06.2015, 11:02 Uhr, schrieb <hemso...@gmail.com>:

> the attachment waybill (Russian)
> in the waybill image with a bar code. Original Size: 600x700
> in document: ~580x70

Thanks. Can you include the code that creates the file? The image itself
isn't resized but I can see in my version of Excel that the printer
settings cause the file to be scaled down to 94 %. Where do you the image
size? I see it as 1.9 x 16.4cm, though the MacOS GUI is a bit different to
the Windows one.

You might try using a 2.3 checkout which uses a relative anchor based on
the top-left cell position, whereas previous versions use absolute
positioning, which also defines the size of the image.

It's probably a good idea to submit a bug report with the file as it is in
openpyxl and how it should be. The image part was based on reverse
engineering and this may have contained some default settings which affect
the display size of the image.

hemso...@gmail.com

unread,
Jun 10, 2015, 10:46:23 AM6/10/15
to openpyx...@googlegroups.com
test code and image

среда, 10 июня 2015 г., 12:39:34 UTC+3 пользователь Charlie Clark написал:
test.png
test.py

Charlie Clark

unread,
Jun 15, 2015, 5:30:22 AM6/15/15
to openpyx...@googlegroups.com
Am .06.2015, 16:46 Uhr, schrieb <hemso...@gmail.com>:

> test code and image

I've had a look at this and I can't actually see anything in the drawing
or image code that affects size so that leaves the scaling to fit to page.
This really needs a more specific bug based on the 2.3 branch (the drawing
code has been completely rewritten and any changes will not be
backported). At the moment it looks to me like expected behaviour.

valery.o...@gmail.com

unread,
Feb 3, 2016, 4:00:28 AM2/3/16
to openpyxl-users, hemso...@gmail.com
So, how to resize image in openpyxl? 

thx

Charlie Clark

unread,
Feb 3, 2016, 7:06:49 AM2/3/16
to openpyx...@googlegroups.com
Am .02.2016, 10:00 Uhr, schrieb <valery.o...@gmail.com>:

> So, how to resize image in openpyxl?

You can't: use pillow to resize an images and pass them into openpyxl.

The issue that this e-mail referred to has been resolved:
https://bitbucket.org/openpyxl/openpyxl/issues/543

jason....@gmail.com

unread,
Aug 11, 2018, 7:11:22 PM8/11/18
to openpyxl-users
Nothing urgent, but it's 2018 and it looks like you've added some code to create a "bounding box" for images in openpyxl.drawing.image :

Though I'm unclear how to use it in conjunction with other openpyxl commands to rescale my images.

Also, I'm new to Python and find it confusing that further down it seems that PIL is required for image to insert images, yet I only have Pillow installed and am not experiencing any issues reading and importing images (other than images overlapping due to their varied sizes).

Anyway, thanks for all this code and help so far!  

- Jason

Charlie Clark

unread,
Aug 12, 2018, 7:35:42 AM8/12/18
to openpyx...@googlegroups.com
Am .08.2018, 01:11 Uhr, schrieb <jason....@gmail.com>:

> Nothing urgent, but it's 2018 and it looks like you've added some code to
> create a "bounding box" for images in openpyxl.drawing.image :
> https://openpyxl.readthedocs.io/en/stable/_modules/openpyxl/drawing/image.html

Welcome to the world of open source: nothing happens unless somebody
decides to do it.

> Though I'm unclear how to use it in conjunction with other openpyxl
> commands to rescale my images.

Join the rest of us! Basically resizing, etc. is handled by the anchor
used to position the image over a worksheet. The only documentation for
this is the OOXML specification.

> Also, I'm new to Python and find it confusing that further down it seems
> that PIL is required for image to insert images, yet I only have Pillow
> installed and am not experiencing any issues reading and importing images
> (other than images overlapping due to their varied sizes).

Pillow is a fork of PIL that was developed when PIL was no longer
maintained. As a result the API is largely unchanged.

Jason H. Fuller

unread,
Sep 14, 2018, 10:38:04 AM9/14/18
to openpyx...@googlegroups.com
Thanks,

I'd love to help, but I hear that I'd need to write unit tests for anything I write.  Is there a good primer on that you recommend? 

- J


--
You received this message because you are subscribed to a topic in the Google Groups "openpyxl-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openpyxl-users/5cVYT7eLDaY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openpyxl-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Charlie Clark

unread,
Sep 18, 2018, 10:33:42 AM9/18/18
to openpyx...@googlegroups.com
Am .09.2018, 21:26 Uhr, schrieb Jason H. Fuller <jason....@gmail.com>:

>
> I'd love to help, but I hear that I'd need to write unit tests for
> anything I write. Is there a good primer on that you recommend?

I learned a lot from Tres Seaver:

https://palladion.com//home/tseaver/obzervationz/2008/unit_testing_notes-20080724

Now, we have a slightly different style in openpyxl and use pytest as the
test framework, but the principles are the same: tests should be as simple
as possible and focussed on testing specific functionality, even if this
blindingly obvious.

You'll need to refer to the pytest docs as there are subtle differences in
the approach between it and unit test.

With openpyxl this generally means checking that the generated XML is
correct. We have pretty extensive test coverage (94%) so there are plenty
of examples to look at.
Reply all
Reply to author
Forward
0 new messages