bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#25583: 26.0.50; :width/:max-width and vice versa in images


From: Lars Ingebrigtsen
Subject: bug#25583: 26.0.50; :width/:max-width and vice versa in images
Date: Tue, 31 Jan 2017 17:02:16 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

>> From: Lars Ingebrigtsen <address@hidden>
>> Date: Mon, 30 Jan 2017 22:42:44 +0100
>> 
>> As far as I can tell, it isn't documented what should happen if you have
>> both :width and :max-height set in image specification, or vice versa.
>
> I see this in the ELisp manual:
>
>   ‘:width WIDTH, :height HEIGHT’
>        The ‘:width’ and ‘:height’ keywords are used for scaling the image.
>        If only one of them is specified, the other one will be calculated
>        so as to preserve the aspect ratio.  If both are specified, aspect
>        ratio may not be preserved.
>
>   ‘:max-width MAX-WIDTH, :max-height MAX-HEIGHT’
>        The ‘:max-width’ and ‘:max-height’ keywords are used for scaling if
>        the size of the image of the image exceeds these values.  If
>        ‘:width’ is set it will have precedence over ‘max-width’, and if
>        ‘:height’ is set it will have precedence over ‘max-height’, but you
>        can otherwise mix these keywords as you wish.  ‘:max-width’ and
>        ‘:max-height’ will always preserve the aspect ratio.
>
> So I think the behavior that should be expected is well documented.

No, the case where :width and :max-height are both specified is not
documented.  Only :width and :max-width (and :height and :max-height).

>> Here's the use case: I want to display images that are mostly square,
>> but can sometimes be rectangular, and I want them to be displayed in max
>> width if possible, even if they are smaller than that width originally,
>> but not exceeding a certain height.
>> 
>> So I thought ":width 400 :max-height 500" should do the trick, but
>> apparently compute_image_size just ignores :max-height in this case.
>> 
>> I think :max-height should "win" here... (That is, the width will end up
>> smaller than 400 if making it 400 wide will make height exceed 500.)
>
> Sorry, I don't understand how :max-height could (or should) affect the
> width.

The aspect ratio is preserved in all these transforms, so changing (or
restricting) the width changes the height and vice versa.

> And where do you see in the code that :max-height is ignored
> if :width is given?  My reading of the code is that that :max-height
> is ignored only if :height is given.

You end up here:

  if (desired_height == -1)
    {
      value = image_spec_value (spec, QCmax_height, NULL);
      if (NATNUMP (value))
        {
          int max_height = min (XFASTINT (value), INT_MAX);
          if (max_height < height)
            desired_height = max_height;
        }
    }

height is not larger than max_height here, so desired_height is not set.

  if (desired_width != -1 && desired_height == -1)
    /* w known, calculate h.  */
    desired_height = scale_image_size (desired_width, width, height);

And then this is done, and :max-height is ignored.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





reply via email to

[Prev in Thread] Current Thread [Next in Thread]