I am trying to make jabber.el support images sent from e.g. Conversations.
I download the image using url-retrieve-synchonously
and call create-image
to get an image which I can then use with insert-image
. This works as expected.
I would like, however, to put a :max-width
and :max-height
on the image. I can add them in the create-image
call, but because create-image
automatically inserts a :width
and a :height
image property, the max-values are ignored, as the manual explains:
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
- https://www.gnu.org/software/emacs/manual/html_node/elisp/ImageMagick-Images.html#ImageMagick-Images
The documentation says that I can remove image properties with setf
, by setting them to nil
:
Function: image-property image property
Return the value of property in image. Properties can be set by using setf. Setting a property to nil will remove the property from the image.
This, however, I can't make work - if I setf
a property to nil
, the key is deleted, but the value isn't, and the image object seems to be messed up.
Example (simplified):
(defun my-fetch-image (url)
"Retun filename of image downloaded from url"
(url-copy-file url "/tmp/test.jpg")
(create-image "/tmp/test.jpg"))
(setq my-image (my-fetch-image "https://koldfront.dk/photo/pics/2018/09/snapshot-22-142810-s.jpg"))
Now, my-image looks like this: (image :type imagemagick :file "/tmp/test.jpg" :scale 1.2019047619047618 :width 288 :height 400)
And when I try to remove width and height:
(setf (image-property my-image :width) nil)
(setf (image-property my-image :height) nil)
I am left with my-image looking like this: (image :type imagemagick :file "/tmp/test.jpg" :scale 1.2019047619047618 288 :height 400)
As you can see :width
got removed, but the value 288
is still there, and :height 400
is untouched.
I'm sure I haven't understood how to use setf
, but I can't find any examples to go by, and my guesses don't yield the result I'm after, either.