From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Re: Image transformations Date: Thu, 25 Jul 2019 21:40:12 +0200 Message-ID: References: <83d0jdv68i.fsf@gnu.org> <20190617211332.GA55597@breton.holly.idiocy.org> <83a7e6na26.fsf@gnu.org> <20190625183352.GA18019@breton.holly.idiocy.org> <838stplcgb.fsf@gnu.org> <83v9wri0yd.fsf@gnu.org> <20190628183604.GA51376@breton.holly.idiocy.org> <83imsph4kj.fsf@gnu.org> <20190629194959.GA71373@breton.holly.idiocy.org> <20190630143846.GA8886@breton.holly.idiocy.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="139673"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Eli Zaretskii , emacs-devel@gnu.org To: Alan Third Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 25 21:40:25 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hqjbD-000aBN-Ls for ged-emacs-devel@m.gmane.org; Thu, 25 Jul 2019 21:40:23 +0200 Original-Received: from localhost ([::1]:35138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqjbC-0002kc-Mm for ged-emacs-devel@m.gmane.org; Thu, 25 Jul 2019 15:40:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33337) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqjb9-0002gp-FP for emacs-devel@gnu.org; Thu, 25 Jul 2019 15:40:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqjb8-0003Xq-2H for emacs-devel@gnu.org; Thu, 25 Jul 2019 15:40:19 -0400 Original-Received: from quimby.gnus.org ([80.91.231.51]:43030) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqjb7-0003Vv-QT; Thu, 25 Jul 2019 15:40:17 -0400 Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=stories) by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hqjb2-0007UP-VI; Thu, 25 Jul 2019 21:40:15 +0200 In-Reply-To: (Lars Ingebrigtsen's message of "Sun, 30 Jun 2019 17:24:44 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 80.91.231.51 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:238899 Archived-At: 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