Converting this jpg ruins it for OSX & iOS (copy-pastable steps to reproduce included)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
kvz
Posts: 4
Joined: 2015-06-04T02:19:31-07:00
Authentication code: 6789

Converting this jpg ruins it for OSX & iOS (copy-pastable steps to reproduce included)

Post by kvz »

Hi,

A customer of ours is trying to convert this jpg: https://www.dropbox.com/s/rd4p6x1f5sx93jd/orig.jpg?dl=1 through our service which relies on imagemagick. When the conversion is done though, the file displays properly on all devices except those running OSX (at least Yosemite) and iOS (at least 8 ).

I wrote a script that can be executed or copy-pasted to reproduce: https://gist.github.com/kvz/a9e2cabd617636db0055:

Code: Select all

#!/usr/bin/env bash
# Transloadit API2. Copyright (c) 2015, Transloadit Ltd.
#
# This file
#  - Reproduces the issue where resizing a certain jpg breaks
#    the image on OSX & iOS, wheras the original dispays fine.
#
# Reported first by Richard Taylor in http://support.transloadit.com/discussions/questions/96479-image-conversion-problem
#
# Typically called as `./debug.sh [target.jpg]`
#
# Authors:
#  - Kevin van Zonneveld <kevin@transloadit.com>

set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace

# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname "${__dir}")" && pwd)"

converVersion="$(convert -version |awk '{print $3}' |head -n1)"
target="${1:-$converVersion}"
ext="jpg"

inFile="${__dir}/orig.${ext}"
outFile="${__dir}/${target}.${ext}"


if [ ! -f "${inFile}" ]; then
  wget "https://www.dropbox.com/s/rd4p6x1f5sx93jd/orig.jpg?dl=1" -O "${inFile}"
fi

rm -f "${outFile}"
convert \
  "${inFile}" \
"${outFile}"

echo ""
echo "${inFile}"
echo exiftool: $(exiftool "${inFile}" |egrep -i '(width|height)' || true)
echo      sips: $(sips -g pixelWidth -g pixelHeight "${inFile}" |egrep -i '(width|height)' || true)
echo ""

echo "${outFile}"
echo exiftool: $(exiftool "${outFile}" |egrep -i '(width|height)' || true)
echo      sips: $(sips -g pixelWidth -g pixelHeight "${outFile}" |egrep -i '(width|height)' || true)
echo ""
As you can see I already stripped all resize arguments to boil it down to just the convert.

After executing, it shows that the original file (orig.jpg) has dimensions according to exiftool & OSX's sips:

Code: Select all

/Users/kvz/code/api2/api2/test/regression/orig.jpg
exiftool: Exif Image Width : 1024 Exif Image Height : 768 Image Width : 1024 Image Height : 768
sips: pixelWidth: 1024 pixelHeight: 768

/Users/kvz/code/api2/api2/test/regression/6.9.1-4.jpg
exiftool: Exif Image Width : 1024 Exif Image Height : 768 Image Width : 1024 Image Height : 768
sips: pixelWidth: <nil> pixelHeight: <nil>
Yet the converted file (6.9.1-4.jpg) also has dimensions according to exiftool, but OSX's sips fails to determine its dimension. When opening in Preview on OSX or Chrome/Safari on iOS, the image does not display at all.

I tried these imagemagick versions, executed from both Ubuntu Precise and OSX Yosemite:

- 6.5.1-0
- 6.8.9-7
- 6.9.1-4

All producing the same broken image. I'd love some help here : )

Kind regards,
Kevin
Last edited by kvz on 2015-06-05T02:02:43-07:00, edited 3 times in total.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Converting this jpg ruins it for OSX & iOS (copy-pastable steps to reproduce included)

Post by dlemstra »

I did not look at the image (on a mobile for now) but is that image a cmyck image? Are you doing any cmyk to rgb conversion?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
kvz
Posts: 4
Joined: 2015-06-04T02:19:31-07:00
Authentication code: 6789

Re: Converting this jpg ruins it for OSX & iOS (copy-pastable steps to reproduce included)

Post by kvz »

Not doing any colorspace conversion no, the command used is:

Code: Select all

convert orig.jpg new.jpg
As for the colorspace itself, sRGB is indicated:

Code: Select all

$ identify orig.jpg
orig.jpg JPEG 1024x768 1024x768+0+0 8-bit sRGB 501KB 0.000u 0:00.000
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting this jpg ruins it for OSX & iOS (copy-pastable steps to reproduce included)

Post by fmw42 »

I am using IM 6.9.1.4 Q16 and my INTEL Mac Mini with Mac OSX Snow Leopard. I did your conversion as above

convert orig.jpg new.jpg

and the file displays fine in my PREVIEW app and in my Safari.
kvz
Posts: 4
Joined: 2015-06-04T02:19:31-07:00
Authentication code: 6789

Re: Converting this jpg ruins it for OSX & iOS (copy-pastable steps to reproduce included)

Post by kvz »

So a Yosemite/iOS8 issue maybe? It was reported by a customer and I could reproduce - leading me to think it's not my machines or clumsiness in this case ; )
kvz
Posts: 4
Joined: 2015-06-04T02:19:31-07:00
Authentication code: 6789

Re: Converting this jpg ruins it for OSX & iOS (copy-pastable steps to reproduce included)

Post by kvz »

I just got word from my customer that iOS 7 and earlier can display the converted image correctly. So it seems only Apple's latests are affected
Post Reply