From: Lars Ingebrigtsen <larsi@gnus.org>
To: Alan Third <alan@idiocy.org>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: Image transformations
Date: Thu, 25 Jul 2019 21:40:12 +0200 [thread overview]
Message-ID: <m3k1c5c38j.fsf@gnus.org> (raw)
In-Reply-To: <m3sgrrxfib.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sun, 30 Jun 2019 17:24:44 +0200")
Nothing further was done here? So just to recap for new viewers who
have recently joined us:
Currently, anybody who wants to insert an image in Emacs has to say the
equivalent of
(create-image data
(if (or (and (fboundp 'image-transforms-p)
(image-transforms-p))
(not (fboundp 'imagemagick-types)))
nil
'imagemagick))
to be somewhat compatible over current Emacses (because we almost always
want to scale images). That's rather a mouthful, so Alan's suggestion
was to just do this in `create-image', but better.
I took that idea and worked it a bit more so that we never use
imagemagick unless we absolutely need to, to satisfy the user's wishes.
Does the following look OK to everybody?
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 3c91092906..d9ac2e0411 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -5757,10 +5757,14 @@ Defining Images
a string containing the image data; @var{data-p} should be @code{nil}
for the former case, non-@code{nil} for the latter case.
-The optional argument @var{type} is a symbol specifying the image type.
-If @var{type} is omitted or @code{nil}, @code{create-image} tries to
-determine the image type from the file's first few bytes, or else
-from the file's name.
+The optional argument @var{type} is a symbol specifying the image
+type. If @var{type} is omitted or @code{nil}, @code{create-image}
+tries to determine the image type from the file's first few bytes, or
+else from the file's name. If @var{props} specify an image transform
+(for instance, @samp{:scale}, @samp{:max-height} or @samp{rotate}),
+and @var{type} is @code{nil}, and Emacs doesn't have the requisite
+native support for that transform, and Emacs is built with ImageMagick
+support, then @var{type} will default to @var{imagemagick} instead.
The remaining arguments, @var{props}, specify additional image
properties---for example,
diff --git a/etc/NEWS b/etc/NEWS
index f47cf071bb..1ce7bba786 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2344,6 +2344,12 @@ The new function 'image-transforms-p' can be used to test whether any
given frame supports these capabilities.
+++
+** If `create-image' is called with a nil TYPE parameter, and a transform
+is specified (:scale, :max-height, :rotate, etc), and Emacs doesn't
+support this natively, and Emacs is built with ImageMagick support,
+then TYPE will default to `imagemagick'.
+
++++
** '(locale-info 'paper)' now returns the paper size on systems that support it.
This is currently supported on GNUish hosts and on modern versions of
MS-Windows.
diff --git a/lisp/image.el b/lisp/image.el
index c3e28655c3..379fda8a51 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -421,6 +421,11 @@ create-image
of image data. If that doesn't work, and FILE-OR-DATA is a file name,
use its file extension as image type.
+If PROPS contain image transforms (like :max-height, :scale,
+:rotate, etc), and we don't support these transforms natively in
+Emacs, and TYPE is nil, and we have ImageMagick support in Emacs,
+then TYPE will default to `imagemagick'.
+
Optional DATA-P non-nil means FILE-OR-DATA is a string containing image data.
Optional PROPS are additional image attributes to assign to the image,
@@ -436,13 +441,35 @@ create-image
Image file names that are not absolute are searched for in the
\"images\" sub-directory of `data-directory' and
`x-bitmap-file-path' (in that order)."
+ (unless (plist-get props :scale)
+ (let ((scale (image-compute-scaling-factor image-scaling-factor)))
+ (unless (= scale 1)
+ (setq props (append (list :scale scale) props)))))
+ ;; Default to ImageMagick if a transform is requested, and we do not
+ ;; have the appropriate native transform, and the type isn't
+ ;; specified.
+ (if (and (not type)
+ (fboundp 'imagemagick-types)
+ ;; All these props require scaling.
+ (or (and (or (plist-get props :scale)
+ (plist-get props :width)
+ (plist-get props :height)
+ (plist-get props :max-width)
+ (plist-get props :max-height))
+ (not (memq 'scale (image-transforms-p))))
+ ;; We can have rotation by 90/180/270 degrees supported
+ ;; natively...
+ (and (plist-get props :rotation)
+ (if (zerop (mod (plist-get props :rotation) 90))
+ (not (memq 'rotate90 (image-transforms-p)))
+ t))
+ ;; We don't currently have native cropping.
+ (plist-get props :crop)))
+ (setq type 'imagemagick))
;; It is x_find_image_file in image.c that sets the search path.
(setq type (image-type file-or-data type data-p))
(when (image-type-available-p type)
(append (list 'image :type type (if data-p :data :file) file-or-data)
- (and (not (plist-get props :scale))
- (list :scale
- (image-compute-scaling-factor image-scaling-factor)))
props)))
(defun image--set-property (image property value)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
next prev parent reply other threads:[~2019-07-25 19:40 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-11 5:10 Image transformations Eli Zaretskii
2019-06-11 20:02 ` Alan Third
2019-06-12 15:30 ` Eli Zaretskii
2019-06-12 22:07 ` Alan Third
2019-06-12 22:15 ` Alan Third
2019-06-13 4:16 ` Alp Aker
2019-06-13 5:41 ` Eli Zaretskii
2019-06-13 9:19 ` Alp Aker
2019-06-13 13:05 ` Eli Zaretskii
2019-06-13 15:57 ` Alp Aker
2019-06-13 16:20 ` Eli Zaretskii
2019-06-13 19:00 ` Richard Copley
2019-06-13 19:29 ` Eli Zaretskii
2019-06-14 10:45 ` Alp Aker
2019-06-14 10:55 ` Richard Copley
2019-06-14 11:45 ` YAMAMOTO Mitsuharu
2019-06-14 11:59 ` Alp Aker
2019-06-13 16:12 ` Alan Third
2019-06-13 17:05 ` Eli Zaretskii
2019-06-13 19:35 ` Richard Copley
2019-06-13 5:48 ` Eli Zaretskii
2019-06-13 16:58 ` Alan Third
2019-06-13 17:11 ` Eli Zaretskii
2019-06-13 19:27 ` Alan Third
2019-06-13 19:39 ` Alan Third
2019-06-13 19:47 ` Eli Zaretskii
2019-06-13 22:26 ` Alan Third
2019-06-14 7:05 ` Eli Zaretskii
2019-06-14 9:57 ` Stefan Monnier
2019-06-14 10:57 ` Eli Zaretskii
2019-06-14 11:21 ` Richard Copley
2019-06-14 12:06 ` Eli Zaretskii
2019-06-14 12:49 ` Richard Copley
2019-06-14 14:16 ` Yuri Khan
2019-06-14 14:43 ` Eli Zaretskii
2019-06-14 15:55 ` Richard Copley
2019-06-15 11:00 ` Alan Third
2019-06-15 11:34 ` Eli Zaretskii
2019-06-15 10:42 ` Alan Third
2019-06-15 11:31 ` Eli Zaretskii
2019-06-16 15:22 ` Alan Third
2019-06-16 16:34 ` Eli Zaretskii
2019-06-17 21:13 ` Alan Third
2019-06-19 17:56 ` Eli Zaretskii
2019-06-24 17:54 ` Eli Zaretskii
2019-06-24 19:50 ` Stefan Monnier
2019-06-25 2:33 ` Eli Zaretskii
2019-06-25 3:28 ` Stefan Monnier
2019-06-25 4:34 ` Eli Zaretskii
2019-06-25 14:43 ` Stefan Monnier
2019-06-25 15:35 ` Eli Zaretskii
2019-06-26 0:28 ` YAMAMOTO Mitsuharu
2019-06-26 15:34 ` Eli Zaretskii
2019-06-27 3:37 ` YAMAMOTO Mitsuharu
2019-06-27 13:13 ` Eli Zaretskii
2019-06-25 18:33 ` Alan Third
2019-06-25 18:57 ` Eli Zaretskii
2019-06-27 13:59 ` Eli Zaretskii
2019-06-28 18:36 ` Alan Third
2019-06-28 19:50 ` Eli Zaretskii
2019-06-29 11:55 ` Eli Zaretskii
2019-06-29 19:51 ` Alan Third
2019-06-29 19:49 ` Alan Third
2019-06-29 19:53 ` Lars Ingebrigtsen
2019-06-30 14:38 ` Alan Third
2019-06-30 15:24 ` Lars Ingebrigtsen
2019-07-25 19:40 ` Lars Ingebrigtsen [this message]
2019-07-26 6:10 ` Eli Zaretskii
2019-07-26 6:46 ` Lars Ingebrigtsen
2019-07-26 8:06 ` Eli Zaretskii
2019-07-26 8:23 ` Lars Ingebrigtsen
2019-07-26 8:24 ` Lars Ingebrigtsen
2019-07-26 8:33 ` Eli Zaretskii
2019-07-26 8:58 ` Lars Ingebrigtsen
2019-07-26 9:13 ` Eli Zaretskii
2019-07-26 10:23 ` Lars Ingebrigtsen
2019-07-26 14:08 ` Stefan Monnier
2019-07-26 8:32 ` Eli Zaretskii
2019-06-29 21:05 ` Stefan Monnier
2019-06-30 15:12 ` Eli Zaretskii
2019-06-30 19:10 ` Alan Third
2019-07-01 14:55 ` Eli Zaretskii
2019-06-18 11:01 ` Tak Kunihiro
2019-06-13 17:41 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3k1c5c38j.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=alan@idiocy.org \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).