* Get the actual width/height of an image
@ 2020-09-14 20:22 Yuan Fu
2020-09-14 20:52 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 7+ messages in thread
From: Yuan Fu @ 2020-09-14 20:22 UTC (permalink / raw)
To: help-gnu-emacs
Here’s what I want to do: I want to show an image in slices, and I want to be able to resize the image to certain width/height. For example, I want to set the width of an image to, say, 300 pixels. IIUC, to show the image in slices I need to now how many rows to use (row-count = image-height / line-height). However, there is no way for me to know what the height should be to make the width to be 300 pixels. There doesn’t seem to be a function to get the aspect ratio of the image, or the actual pixel height/width of the image. So can I get this information?
Thanks,
Yuan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Get the actual width/height of an image
2020-09-14 20:22 Get the actual width/height of an image Yuan Fu
@ 2020-09-14 20:52 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-09-14 21:18 ` Corwin Brust
0 siblings, 1 reply; 7+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-09-14 20:52 UTC (permalink / raw)
To: help-gnu-emacs
Yuan Fu wrote:
> There doesn’t seem to be a function to get the
> aspect ratio of the image, or the actual pixel
> height/width of the image. So can I get
> this information?
For everything batch and graphics, use ImageMagick.
For the specific problem, you can use the command
identify(1) which is part of ImageMagick.
$ identify zhanna-friske.png
zhanna-friske.png PNG 1280x720 1280x720+0+0 8-bit sRGB 835952B 0.000u 0:00.000
You can then parse the output to answer an even more
specific question, e.g. what the height is:
#! /bin/zsh
pic-height () {
local img=$1
identify $img | awk '{print $3}' | cut -d 'x' -f 2
}
$ pic-height zhanna-friske.png
720
https://dataswamp.org/~incal/conf/.zsh/gfx
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Get the actual width/height of an image
2020-09-14 20:52 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-09-14 21:18 ` Corwin Brust
2020-09-14 21:40 ` Yuan Fu
2020-09-14 22:20 ` Stefan Monnier
0 siblings, 2 replies; 7+ messages in thread
From: Corwin Brust @ 2020-09-14 21:18 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
Greetings!
On Mon, Sep 14, 2020 at 3:53 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Yuan Fu wrote:
>
> > There doesn’t seem to be a function to get the
> > aspect ratio of the image, or the actual pixel
> > height/width of the image. So can I get
> > this information?
I think we can get the dimensions from `image-size', but note the
PIXELS argument:
(image-size SPEC &optional PIXELS FRAME)
| Documentation
| Return the size of image SPEC as pair (WIDTH . HEIGHT).
| PIXELS non-nil means return the size in pixels, otherwise return the
| size in canonical character units.
| FRAME is the frame on which the image will be displayed. FRAME nil
| or omitted means use the selected frame.
| Calling this function will result in the image being stored in the
| image cache. If this is not desirable, call image-flush after
| calling this function.
> For everything batch and graphics, use ImageMagick.
I think Emacs is moving away from ImageMagick and toward
"self-implemented" image manipulation &ct. functions. Not that IM
has "gotten rusty" -- it isn't preferred from an elisp perspective
which could be important in terms of portability to other Emacsen.
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
Regards,
Corwin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Get the actual width/height of an image
2020-09-14 21:18 ` Corwin Brust
@ 2020-09-14 21:40 ` Yuan Fu
2020-09-14 22:20 ` Stefan Monnier
1 sibling, 0 replies; 7+ messages in thread
From: Yuan Fu @ 2020-09-14 21:40 UTC (permalink / raw)
To: Corwin Brust; +Cc: help-gnu-emacs, Emanuel Berg
> On Sep 14, 2020, at 5:18 PM, Corwin Brust <corwin@bru.st> wrote:
>
> Greetings!
>
> On Mon, Sep 14, 2020 at 3:53 PM Emanuel Berg via Users list for the
> GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>>
>> Yuan Fu wrote:
>>
>>> There doesn’t seem to be a function to get the
>>> aspect ratio of the image, or the actual pixel
>>> height/width of the image. So can I get
>>> this information?
>
>
> I think we can get the dimensions from `image-size', but note the
> PIXELS argument:
>
> (image-size SPEC &optional PIXELS FRAME)
>
> | Documentation
> | Return the size of image SPEC as pair (WIDTH . HEIGHT).
>
> | PIXELS non-nil means return the size in pixels, otherwise return the
> | size in canonical character units.
>
> | FRAME is the frame on which the image will be displayed. FRAME nil
> | or omitted means use the selected frame.
>
> | Calling this function will result in the image being stored in the
> | image cache. If this is not desirable, call image-flush after
> | calling this function.
>
>
Wow, exactly what I want! Wonder why I missed it when reading Info. Thanks!
Yuan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Get the actual width/height of an image
2020-09-14 21:18 ` Corwin Brust
2020-09-14 21:40 ` Yuan Fu
@ 2020-09-14 22:20 ` Stefan Monnier
2020-09-15 0:13 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2020-09-14 22:20 UTC (permalink / raw)
To: help-gnu-emacs
> I think Emacs is moving away from ImageMagick and toward
> "self-implemented" image manipulation &ct. functions. Not that IM
> has "gotten rusty" -- it isn't preferred from an elisp perspective
> which could be important in terms of portability to other Emacsen.
Actually, yes, part of the reason is that it has gotten rusty, IIRC.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Get the actual width/height of an image
2020-09-14 22:20 ` Stefan Monnier
@ 2020-09-15 0:13 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-09-15 13:43 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-09-15 0:13 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier wrote:
>> I think Emacs is moving away from ImageMagick and
>> toward "self-implemented" image manipulation &ct.
>> functions. Not that IM has "gotten rusty" -- it
>> isn't preferred from an elisp perspective which
>> could be important in terms of portability to
>> other Emacsen.
>
> Actually, yes, part of the reason is that it has
> gotten rusty, IIRC.
Well, if that is the reason perhaps efforts should be
made to remove the rust (actually, things that you
use typically don't rust) rather than have every
software project's team of developers implementing
their own way of getting the dimensions of an
image? ;)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-09-15 13:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-14 20:22 Get the actual width/height of an image Yuan Fu
2020-09-14 20:52 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-09-14 21:18 ` Corwin Brust
2020-09-14 21:40 ` Yuan Fu
2020-09-14 22:20 ` Stefan Monnier
2020-09-15 0:13 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-09-15 13:43 ` Stefan Monnier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).