GNU bug report logs - #40978
28.0.50; create-image and find-image consistency

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: David Ponce <da_vid@HIDDEN>; merged with #47039; Done: Lars Ingebrigtsen <larsi@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
bug marked as fixed in version 29.1, send any further explanations to 47039 <at> debbugs.gnu.org and ynyaaa@HIDDEN Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 40978 <at> debbugs.gnu.org:


Received: (at 40978) by debbugs.gnu.org; 20 Jun 2022 09:39:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jun 20 05:39:08 2022
Received: from localhost ([127.0.0.1]:54370 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1o3DsC-0006n5-M1
	for submit <at> debbugs.gnu.org; Mon, 20 Jun 2022 05:39:08 -0400
Received: from quimby.gnus.org ([95.216.78.240]:60668)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>)
 id 1o3DsB-0006mb-0n; Mon, 20 Jun 2022 05:39:07 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=MEqUwnJEF+UFiU4J6QmTg8QnIu2+OothhalCE9E4Hjw=; b=cbTtLVxm+phyz7RRhdxQF+jxHe
 I/SbGKZTn63HWoHGun0GSk083yKqPnz9bJfVe2u3saAiVcJfonq7JtdeI2avM/xtrdh+e9d+zHyH8
 g3rEzQz6wSuctdAegyPPlMtGj+NMt/58TvmGCoPi6fOmix2YMKTDBNCPG8IYZRRuezZk=;
Received: from [84.212.220.105] (helo=xo)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1o3Ds2-0008Q5-57; Mon, 20 Jun 2022 11:39:00 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: David Ponce <da_vid@HIDDEN>
Subject: Re: bug#47039: 27.1; find-image ignores image-scaling-factor
References: <3a9c34ae-8052-d634-78c3-e83a2f6b6624@HIDDEN>
 <87ees536hl.fsf@HIDDEN>
 <dd80335a-54cd-80ba-ed1e-8be9b7e8278e@HIDDEN>
 <87o8r8zl16.fsf@HIDDEN>
X-Now-Playing: Was (Not Was)'s _Mutant Disco Volume 2_: "Tell Me That I'm
 Dreaming"
Date: Mon, 20 Jun 2022 11:38:57 +0200
In-Reply-To: <87o8r8zl16.fsf@HIDDEN> (Lars Ingebrigtsen's message of "Fri,
 01 May 2020 00:05:57 +0200")
Message-ID: <87h74f4qtq.fsf_-_@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview:  Lars Ingebrigtsen <larsi@HIDDEN> writes: >> IMHO,
 auto-scaling
 is particularly useful with graphics elements like >> tool bars, tab bars,
 and widgets ;-) > > Yeah, that's true. I think. I was finally reminded that
 I should try David's patch after looking at a --with-x-toolkit=lucid build
 where all the toolbar icons were minuscule on this 4K 14" laptop screen. 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 40978
Cc: 47039 <at> debbugs.gnu.org, 40978 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Lars Ingebrigtsen <larsi@HIDDEN> writes:

>> IMHO, auto-scaling is particularly useful with graphics elements like
>> tool bars, tab bars, and widgets ;-)
>
> Yeah, that's true.  I think.

I was finally reminded that I should try David's patch after looking at
a --with-x-toolkit=lucid build where all the toolbar icons were
minuscule on this 4K 14" laptop screen.

And it does indeed fix these issues, as well as the tiny "Gnu" logo in
the Gnus Group mode line, etc.

So I've now pushed it to Emacs 29.

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




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#40978; Package emacs. Full text available.
Forcibly Merged 40978 47039. Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 40978 <at> debbugs.gnu.org:


Received: (at 40978) by debbugs.gnu.org; 30 Apr 2020 22:06:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 30 18:06:18 2020
Received: from localhost ([127.0.0.1]:47858 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jUHJy-0006In-FX
	for submit <at> debbugs.gnu.org; Thu, 30 Apr 2020 18:06:18 -0400
Received: from quimby.gnus.org ([95.216.78.240]:60348)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1jUHJm-0006I4-V3
 for 40978 <at> debbugs.gnu.org; Thu, 30 Apr 2020 18:06:17 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=MQwKskcXuIixlB7WEruzzj5pfVNIBEcEjd/chep05Ss=; b=lINfX+LwDjcMockdp/d4TnGQdd
 B3OdWA0utAZBnaZt3BonY3YYRBafjCKAS/8otG1JqfPmETmaUuIFZR1Q68XfotPGcakyDiGmYezcJ
 vvD+cYzIZVjCkHQhrWPIwbblCKkDmzp+9JiDILWhXEu6WSCz9x82Z3nwsTQtLrxJYkl8=;
Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=marnie)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1jUHJe-0000Wg-5n; Fri, 01 May 2020 00:06:00 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: David Ponce <da_vid@HIDDEN>
Subject: Re: bug#40978: create-image and find-image consistency
References: <3a9c34ae-8052-d634-78c3-e83a2f6b6624@HIDDEN>
 <87ees536hl.fsf@HIDDEN>
 <dd80335a-54cd-80ba-ed1e-8be9b7e8278e@HIDDEN>
Date: Fri, 01 May 2020 00:05:57 +0200
In-Reply-To: <dd80335a-54cd-80ba-ed1e-8be9b7e8278e@HIDDEN> (David Ponce's
 message of "Thu, 30 Apr 2020 11:24:30 +0200")
Message-ID: <87o8r8zl16.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: David Ponce <da_vid@HIDDEN> writes: > My idea was to
 better
 separate the role of find-image from > create-image: > > - create-image to
 actually make a new image based on given specs, and > maybe some common options
 and device capabiliti [...] 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 40978
Cc: 40978 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

David Ponce <da_vid@HIDDEN> writes:

> My idea was to better separate the role of find-image from
> create-image:
>
> - create-image to actually make a new image based on given specs, and
>   maybe some common options and device capabilities (for example, auto
>   scaling based on screen resolution).
>   - find-image to lookup for an image in the file system or in raw
>    data,
>   but delegating to create-image the actual creation of the image.

Yes, I think that's a good idea.

> IMHO, auto-scaling is particularly useful with graphics elements like
> tool bars, tab bars, and widgets ;-)

Yeah, that's true.  I think.

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




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#40978; Package emacs. Full text available.

Message received at 40978 <at> debbugs.gnu.org:


Received: (at 40978) by debbugs.gnu.org; 30 Apr 2020 09:24:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 30 05:24:55 2020
Received: from localhost ([127.0.0.1]:45370 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jU5Qu-0008Rw-1v
	for submit <at> debbugs.gnu.org; Thu, 30 Apr 2020 05:24:54 -0400
Received: from smtp10.smtpout.orange.fr ([80.12.242.132]:26995
 helo=smtp.smtpout.orange.fr)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <da_vid@HIDDEN>) id 1jU5Qt-0008Ri-14
 for 40978 <at> debbugs.gnu.org; Thu, 30 Apr 2020 05:24:39 -0400
Received: from [192.168.1.25] ([92.129.178.87]) by mwinf5d88 with ME
 id YxQX220061tXeyc03xQX66; Thu, 30 Apr 2020 11:24:32 +0200
X-ME-Helo: [192.168.1.25]
X-ME-Auth: ZGFfdmlkQHdhbmFkb28uZnI=
X-ME-Date: Thu, 30 Apr 2020 11:24:32 +0200
X-ME-IP: 92.129.178.87
Subject: Re: create-image and find-image consistency
To: Lars Ingebrigtsen <larsi@HIDDEN>
References: <3a9c34ae-8052-d634-78c3-e83a2f6b6624@HIDDEN>
 <87ees536hl.fsf@HIDDEN>
From: David Ponce <da_vid@HIDDEN>
Message-ID: <dd80335a-54cd-80ba-ed1e-8be9b7e8278e@HIDDEN>
Date: Thu, 30 Apr 2020 11:24:30 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.7.0
MIME-Version: 1.0
In-Reply-To: <87ees536hl.fsf@HIDDEN>
Content-Type: text/plain; charset=iso-8859-15; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 40978
Cc: 40978 <at> debbugs.gnu.org, emacs-devel@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

On 30/04/2020 07:08, Lars Ingebrigtsen wrote:
> 
> I think it conceptually makes sense to have find-image use create-image,
> but looking at the code, and where find-image is used, it looks like the
> use case it for creating toolbars and the like, where you want to pick
> out one of the (built-in) image formats that Emacs supports...
> 
> Looking at your patch, you remove the (image-type-available-p type), and
> instead rely on create-image not bugging out instead?  That feels like a
> less obvious way to do the test (and more breakable; there may be other
> reasons create-image fails).
> 
> And I'm not 100% sure that we want to auto-scale toolbars and the like.
> I'm pretty sure we do, but perhaps somebody else has an opinion here?
> 
> Anyway, I think you should file this as a bug report so that the patch
> doesn't get lost, because I think you're basically correct that the
> find-image behaviour should be changed.
> 

Hi Lars,

I created bug report #40978 as suggested.

My idea was to better separate the role of find-image from
create-image:

- create-image to actually make a new image based on given specs, and
   maybe some common options and device capabilities (for example, auto
   scaling based on screen resolution).
   
- find-image to lookup for an image in the file system or in raw data,
   but delegating to create-image the actual creation of the image.

Currently find-image & create-image can return a different image from
the same spec, which is not consistent. My patch proposes to fix such
potential inconsistencies.
When you don't need auto-scaling for example, you can pass :scale 1.0
to find-image, like you would have done with create-image :-)
IMHO, auto-scaling is particularly useful with graphics elements like
tool bars, tab bars, and widgets ;-)

Thanks for taking into account this proposal!




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#40978; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 30 Apr 2020 08:53:46 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 30 04:53:46 2020
Received: from localhost ([127.0.0.1]:45339 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jU4wv-0007gy-NR
	for submit <at> debbugs.gnu.org; Thu, 30 Apr 2020 04:53:46 -0400
Received: from lists.gnu.org ([209.51.188.17]:38476)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <da_vid@HIDDEN>) id 1jU4wu-0007gr-L6
 for submit <at> debbugs.gnu.org; Thu, 30 Apr 2020 04:53:41 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:44034)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <da_vid@HIDDEN>) id 1jU4wt-0006QX-6G
 for bug-gnu-emacs@HIDDEN; Thu, 30 Apr 2020 04:53:40 -0400
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
 RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,URIBL_BLOCKED
 autolearn=unavailable autolearn_force=no version=3.4.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1)
 (envelope-from <da_vid@HIDDEN>) id 1jU4wn-0003c9-Me
 for bug-gnu-emacs@HIDDEN; Thu, 30 Apr 2020 04:53:38 -0400
Received: from smtp10.smtpout.orange.fr ([80.12.242.132]:22335
 helo=smtp.smtpout.orange.fr)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128)
 (Exim 4.90_1) (envelope-from <da_vid@HIDDEN>) id 1jU4wm-0003UW-S8
 for bug-gnu-emacs@HIDDEN; Thu, 30 Apr 2020 04:53:33 -0400
Received: from [192.168.1.25] ([92.129.178.87]) by mwinf5d88 with ME
 id YwtS2200m1tXeyc03wtTdV; Thu, 30 Apr 2020 10:53:27 +0200
X-ME-Helo: [192.168.1.25]
X-ME-Auth: ZGFfdmlkQHdhbmFkb28uZnI=
X-ME-Date: Thu, 30 Apr 2020 10:53:27 +0200
X-ME-IP: 92.129.178.87
Subject: 28.0.50; create-image and find-image consistency
References: <3a9c34ae-8052-d634-78c3-e83a2f6b6624@HIDDEN>
To: bug-gnu-emacs@HIDDEN
From: David Ponce <da_vid@HIDDEN>
X-Forwarded-Message-Id: <3a9c34ae-8052-d634-78c3-e83a2f6b6624@HIDDEN>
Message-ID: <f11cfb02-5275-ec4a-e413-bc926ccb7d3f@HIDDEN>
Date: Thu, 30 Apr 2020 10:53:26 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.7.0
MIME-Version: 1.0
In-Reply-To: <3a9c34ae-8052-d634-78c3-e83a2f6b6624@HIDDEN>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 8bit
Received-SPF: none client-ip=80.12.242.132; envelope-from=da_vid@HIDDEN;
 helo=smtp.smtpout.orange.fr
X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/30 04:53:28
X-ACL-Warn: Detected OS   = Linux 2.6.x [fuzzy]
X-Received-From: 80.12.242.132
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Hello dear Emacs developers,

I am using Emacs latest master, and noticed some inconsistency between the
results of function `create-image' and `find-image'.

Here is an example:

(create-image "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg")
==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg" :scale 1.2)

(find-image '((:type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg")))
==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg")

Contrary to images returned by `create-image', which are automatically scaled
when no :scale property is provided, those returned by `find-image' are not.

I propose the below patch to have `find-image' use `create-image' in order to get
consistent results from both functions. Another advantage of using `create-image' is
that it is no longer necessary to provide the :type property to `find-image'.
The correct type is determined by `create-image' with the proper default scaling.

Here is the result of previous example with patched `find-image':

(find-image '((:file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg")))
==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg" :scale 1.2)

Please eventually consider this enhancement to Emacs, if it makes sense.

Thanks & regards,
David Ponce

diff --git a/installs/emacs/lisp/image.el b/emacs.d/image.el
index 4ea8594..046af95 100644
--- a/installs/emacs/lisp/image.el
+++ b/emacs.d/image.el
@@ -687,13 +687,15 @@ SPECS is a list of image specifications.
   
   Each image specification in SPECS is a property list.  The contents of
   a specification are image type dependent.  All specifications must at
-least contain the properties `:type TYPE' and either `:file FILE' or
-`:data DATA', where TYPE is a symbol specifying the image type,
-e.g. `xbm', FILE is the file to load the image from, and DATA is a
-string containing the actual image data.  The specification whose TYPE
-is supported, and FILE exists, is used to construct the image
-specification to be returned.  Return nil if no specification is
-satisfied.
+least contain the either the property `:file FILE' or `:data DATA',
+where FILE is the file to load the image from, and DATA is a string
+containing the actual image data.  If the property `:type TYPE' is
+omitted or nil, try to determine the image type from its first few
+bytes of image data.  If that doesn’t work, and the property `:file
+FILE' provide a file name, use its file extension as image type. If
+the property `:type TYPE' is provided, it must match the actual type
+determined for FILE or DATA by `create-image'.  Return nil if no
+specification is satisfied.
   
   The image is looked for in `image-load-path'.
   
@@ -703,16 +705,39 @@ Image files should not be larger than specified by `max-image-size'."
         (let* ((spec (car specs))
   	     (type (plist-get spec :type))
   	     (data (plist-get spec :data))
-	     (file (plist-get spec :file))
-	     found)
-	(when (image-type-available-p type)
-	  (cond ((stringp file)
-		 (if (setq found (image-search-load-path file))
-		     (setq image
-			   (cons 'image (plist-put (copy-sequence spec)
-						   :file found)))))
-		((not (null data))
-		 (setq image (cons 'image spec)))))
+	     (file (plist-get spec :file)))
+	(cond
+         ((stringp file)
+	  (when (setq file (image-search-load-path file))
+            ;; At this point, remove the :type and :file properties.
+            ;; `create-image' will set them depending on image file.
+            (setq image (cons 'image (copy-sequence spec)))
+            (setf (image-property image :type) nil)
+            (setf (image-property image :file) nil)
+            (and (setq image (ignore-errors
+                               (apply #'create-image file nil nil
+                                      (cdr image))))
+                 ;; Ensure, if a type has been provided, it is
+                 ;; consistent with the type returned by
+                 ;; `create-image'. If not, return nil.
+                 (not (null type))
+                 (not (eq type (image-property image :type)))
+                 (setq image nil))))
+	  ((not (null data))
+            ;; At this point, remove the :type and :data properties.
+            ;; `create-image' will set them depending on image data.
+           (setq image (cons 'image (copy-sequence spec)))
+           (setf (image-property image :type) nil)
+           (setf (image-property image :data) nil)
+	   (and (setq image (ignore-errors
+                              (apply #'create-image data nil t
+                                     (cdr image))))
+                ;; Ensure, if a type has been provided, it is
+                ;; consistent with the type returned by
+                ;; `create-image'. If not, return nil.
+                (not (null type))
+                (not (eq type (image-property image :type)))
+                (setq image nil))))
   	(setq specs (cdr specs))))
       image))
   

-------- Forwarded Message --------
From: Juri Linkov <juri@HIDDEN>
To: David Ponce <da_vid@HIDDEN>
Subject: Re: create-image and find-image consistency
Date: Mon, 20 Apr 2020 02:24:14 +0300

> I propose the below patch to have `find-image' use `create-image' in order to get
> consistent results from both functions. Another advantage of using `create-image' is
> that it is no longer necessary to provide the :type property to `find-image'.
> The correct type is determined by `create-image' with the proper default scaling.
>
> Here is the result of previous example with patched `find-image':
>
> (find-image '((:file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg")))
> ==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg" :scale 1.2)
>
> Please eventually consider this enhancement to Emacs, if it makes sense.

I haven't tested it yet, but it makes sense indeed.

-------- Forwarded Message --------
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: David Ponce <da_vid@HIDDEN>
Cc: emacs-devel@HIDDEN
Subject: Re: create-image and find-image consistency
Date: Thu, 30 Apr 2020 07:08:54 +0200

David Ponce <da_vid@HIDDEN> writes:

> I am using Emacs latest master, and noticed some inconsistency between the
> results of function `create-image' and `find-image'.
>
> Here is an example:
>
> (create-image "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg")
> ==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg" :scale 1.2)
>
> (find-image '((:type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg")))
> ==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg")
>
> Contrary to images returned by `create-image', which are automatically scaled
> when no :scale property is provided, those returned by `find-image' are not.
>
> I propose the below patch to have `find-image' use `create-image' in
> order to get consistent results from both functions.

I think it conceptually makes sense to have find-image use create-image,
but looking at the code, and where find-image is used, it looks like the
use case it for creating toolbars and the like, where you want to pick
out one of the (built-in) image formats that Emacs supports...

Looking at your patch, you remove the (image-type-available-p type), and
instead rely on create-image not bugging out instead?  That feels like a
less obvious way to do the test (and more breakable; there may be other
reasons create-image fails).

And I'm not 100% sure that we want to auto-scale toolbars and the like.
I'm pretty sure we do, but perhaps somebody else has an opinion here?

Anyway, I think you should file this as a bug report so that the patch
doesn't get lost, because I think you're basically correct that the
find-image behaviour should be changed.

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





Acknowledgement sent to David Ponce <da_vid@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#40978; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 20 Jun 2022 09:45:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.