From b074bd9ce763c624f7e20344f8330ea4aed85efb Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 17 Apr 2026 18:12:18 +0200 Subject: [PATCH] Fix JXL orientation when writing. (#8673) JXL documentation told us to ignore EXIF because orientation is encoded in the stream itself. ImageMagick was keeping the EXIF but not setting the stream. Both should be kept and synchronized. --- coders/jxl.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/coders/jxl.c b/coders/jxl.c index 72cf37a7de..ed481a60df 100644 --- a/coders/jxl.c +++ b/coders/jxl.c @@ -191,6 +191,31 @@ static inline StorageType JXLDataTypeToStorageType(Image *image, } } +static inline JxlOrientation OrientationToJXLOrientation( + const OrientationType orientation) +{ + switch (orientation) + { + default: + case TopLeftOrientation: + return(JXL_ORIENT_IDENTITY); + case TopRightOrientation: + return(JXL_ORIENT_FLIP_HORIZONTAL); + case BottomRightOrientation: + return(JXL_ORIENT_ROTATE_180); + case BottomLeftOrientation: + return(JXL_ORIENT_FLIP_VERTICAL); + case LeftTopOrientation: + return(JXL_ORIENT_TRANSPOSE); + case RightTopOrientation: + return(JXL_ORIENT_ROTATE_90_CW); + case RightBottomOrientation: + return(JXL_ORIENT_ANTI_TRANSPOSE); + case LeftBottomOrientation: + return(JXL_ORIENT_ROTATE_90_CCW); + } +} + static inline OrientationType JXLOrientationToOrientation( const JxlOrientation orientation) { @@ -1111,6 +1136,7 @@ static MagickBooleanType WriteJXLImage(const ImageInfo *image_info,Image *image, basic_info.animation.tps_denominator=1; JxlEncoderInitFrameHeader(&frame_header); } + basic_info.orientation=OrientationToJXLOrientation(image->orientation); jxl_status=JxlEncoderSetBasicInfo(jxl_info,&basic_info); if (jxl_status != JXL_ENC_SUCCESS) {