Subject: 29.0.50; image-crop/image-elide + save-buffer creates invalid image file

From: Stefan Kangas <[email-masked]>
Date: Tue, 13 Sep 2022 23:13:48 -0700

I can save an invalid image with image-crop.el using this recipe:

0. emacs -Q some-image.jpg
1. c
2. Drag region
3. RET
4. C-x C-s (`save-buffer')

Now I have two image files:

    some-image.jpg      [invalid, doesn't open]
    some-image.jpg~     [the original file]

Should we just disable `C-x C-s' if it's not a "plain text" image
(e.g. an SVG)?

Also, how about moving `image-save' from "o" to "C-x C-s", while making
sure it does TRT?

In GNU Emacs 29.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version
 3.24.24, cairo version 1.16.0) of 2022-09-14 built on joffe
Repository revision: fb42627c37f09f47119020c878ea0e76687009ff
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --with-native-compilation'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3
THREADS TIFF TOOLKIT_SCROLL_BARS WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LC_COLLATE: C
  value of $LC_CTYPE: sv_SE.UTF-8
  value of $LC_TIME: C
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Dired by name

Minor modes in effect:
  shell-dirtrack-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort hashcash mail-extr emacsbug message mailcap yank-media puny
rfc822 mml mml-sec epa derived epg rfc6068 epg-config gnus-util
text-property-search time-date mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils etags fileloop generator xref
project files-x shell pcomplete comint ansi-color ring misearch
multi-isearch ffap thingatpt url-parse auth-source eieio eieio-core
password-cache json map byte-opt url-vars format-spec image-crop svg dom
xml image-mode exif comp comp-cstr warnings subr-x rx cl-seq cl-macs gv
cl-extra help-mode bytecomp byte-compile cconv dired-aux cus-edit pp
cus-start cus-load icons wid-edit cl-loaddefs cl-lib dired
dired-loaddefs rmc iso-transl tooltip eldoc paren electric uniquify
ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget keymap hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit xinput2 x multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 139550 12499)
 (symbols 48 11190 0)
 (strings 32 35573 7703)
 (string-bytes 1 8894362)
 (vectors 16 25900)
 (vector-slots 8 437332 24658)
 (floats 8 71 58)
 (intervals 56 1571 233)
 (buffers 1000 14))