emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Timothy <tecosaur@gmail.com>
To: Org-Mode Mailing List <emacs-orgmode@gnu.org>
Subject: [PATCH] Prevent displayed images from being re-scaled
Date: Wed, 29 Sep 2021 21:33:34 +0800	[thread overview]
Message-ID: <87bl4bcxe3.fsf@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 922 bytes --]


After my last patch providing support for proportional image width attributes
(e.g. 70% of the text width), I noticed that the results looked slightly off.
Investigating the code lead me to `create-image' which takes the liberty of
re-scaling images based on your default font size. As you might imagine, this
can be problematic when if you say determine that image should be 70% of the
text width, the text width is 1000px, and so the image should be 700px wide —
but upon being told to make the image 700 pixels wide `create-image' decides to
make it say 850 pixels wide. I personally found that images >~80% wide were
being made wider than the buffer, which isn’t good.

To make image width behave as expected, we can just specify `:scale 1' when
calling `create-image', and that will stop it from re-interpreting the `:width'
specification. See the patch attached.

All the best,

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Don-t-change-image-size-based-on-font-size.patch --]
[-- Type: text/x-patch, Size: 1113 bytes --]

From 9c34dd6aba62d734f6ae9aecaffa76a0250bf495 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 29 Sep 2021 21:29:27 +0800
Subject: [PATCH] org: Don't change image size based on font size

* lisp/org.el (org--create-inline-image): When `create-image' is called
without the :scale parameter, the image size is expanded based on the
default font size (if it is larger than 10px).  When displaying images
with a specified width in Org buffers, either in pixels or proportional
to the text width, this width should not be modified according the to
font size.  Giving a :scale parameter of 1 prevents this font-size based
 lisp/org.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 2ec6566c0..0e7f926f0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16518,7 +16518,7 @@ (defun org--create-inline-image (file width)
-		    :width width))))
+		    :width width :scale 1))))
 (defun org-display-inline-images (&optional include-linked refresh beg end)
   "Display inline images.

             reply	other threads:[~2021-09-29 13:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 13:33 Timothy [this message]
2021-10-02 20:30 ` [PATCH] Prevent displayed images from being re-scaled Timothy
2021-10-25 13:49   ` Timothy
2021-10-03  4:57 ` Bastien
2021-10-03  5:45   ` Timothy

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:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bl4bcxe3.fsf@gmail.com \
    --to=tecosaur@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* 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


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).