imagemagick: follow orientation from exif data - imagemagick

About the ImageMagick command bellow:
imagemagick\convert.exe original.jpg -resize 100x400^ -gravity Center -crop 100x400+0+0 -sharpen 0x0.75 -quality 98% thumbnail.jpg
Some thumbnails generated (in a batch proccess) are not following the original's EXIF data. So they are being generated with the wrong angle. (+|- 90°)
Is there a way to command IM to read the exif data before converting it?

You'll need to add the -auto-orient option.
This operator reads and resets the EXIF image profile setting
'Orientation' and then performs the appropriate 90 degree rotation on
the image to orient the image, for correct viewing.
Example
convert original.jpg -auto-orient -resize 100x400^ \
-gravity Center -crop 100x400+0+0 \
-sharpen 0x0.75 -quality 98% \
thumbnail.jpg

Related

imagemagick combine leads to rotated image

I use the following command to add a watermark to an image (composite). After that the image is rotated by 180d. The convert command has the -auto-orient option, the composite command hasn't such an option. What I have to do, to have the output image not rotated by 180d?
composite -interlace None +profile '!iptc,*' -compose screen -geometry +30+30 -gravity southeast watermark.png example.jpeg test.jpeg

Merge two Imagemagick convert commands

I'm trying to Create a thumbnail from GIF 1st command and then merge another image on top of it 2nd command.
1st command:-
convert -thumbnail 398x398 -auto-orient -quality 85 giphy.gif[0] output.jpg
2nd command:- convert -size 1920x1080 xc:none output.jpg -blur 5x4 -composite out1.png -gravity center -composite outfinal.png
I've tried using like this but didn't work out:
convert -thumbnail 398x398 -auto-orient -quality 85 giphy.gif[0] output.jpg | convert -size 398x398 xc:none output.jpg -blur 5x4 -composite out1.png -gravity center -composite outfinal.png
Image extracted from gif:-
2nd image:
Final output as merge two images :
Thank you:)
This is a pretty easy way to do it:
convert -gravity center background.jpg -blur 5x4 \
\( yinyang.png -resize 130x78\! \) \
-composite result.jpg
I put a spurious -resize 130x78\! in there so you can see where to do extra operations that only affect the little "yin yang" picture in the middle - you can obviously remove it.
Maybe I can explain the logic... the first line of the command deals with the background, the second line deals with the overlay. So, first, load up the background picture and make all the edits you want to it, i.e. blurring. Then start some "aside-processing" in parentheses which loads up the "yin yang" and applies some edits to that exclusively without affecting the background image. Then, when you are happy with the overlay, exit the parentheses and take the result of the "aside-processing" and overlay it on top of the background. It overlays into the centre because I set the gravity beforehand.
Hope that helps.
Added in response to your comment... if you want to do the extraction as well, just do that in the "aside-processing":
convert -gravity center \
giphy.gif[0] -thumbnail 398x398 -auto-orient -blur 5x4 \
\( yin yang -resize 300x100\! \) \
-composite result.jpg

Assembling an image from parts of others with ImageMagick (image crop syntax)

I have a set of source PNG images and I want to use parts of them to assemble a final PNG image. The parts are rectangular and never overlap on the destination but are of different sizes. Sometimes it is the whole of a source image and sometimes just a subsection. I want to edit the sources many times and re-assemble the final image each time, so I tried to write a script using sh and Imagemagick to do it.
I tried this
convert \
-size 512x512 null:\
-page +96+32 source_a.png\
-page +96+0 source_b.png[32x32+16+16] \
-background transparent\
-layers merge\
destination.png
(just with two source images for illustration)
I want all of source_a.png and a piece of source_b.png. The first is OK, but using the 'inline crop' syntax on source_b.png gives me an error:
convert: geometry does not contain image `source_b.png' # warning/transform.c/CropImage/666.
The image is big enough:
$ identify source_b.png
source_b.png PNG 64x48 64x48+0+0 8-bit sRGB 3.7KB 0.000u 0:00.000
What's the best way to do this? I am using ImageMagick 6.9.7-0 Q16 on MacOS 10.12
An alternative might be to use -geometry and -composte to achieve the same effect:
convert -size 512x512 xc:white \
source_a.png -geometry +96+32 -composite \
source_b.png[32x32+16+16] -geometry +96+0 -composite \
result.png
PNG's will preserve the paging from inline cropping, so the addition page will through the ROI out of bounds. I imaging it'll be simpler to -repage the inline crop then attempting to clear previous paging & setting new page.
convert -size 512x512 null: \
-page +96+32 source_a.png \
\( source_b.png[32x32+16+16] -repage +96+0 \) \
-background transparent\
-layers merge\
destination.png

ImageMagick convert rotate crop

The rotate option in ImageMagick's convert tool rotates the image but adds background color to fill the gaps.
I'm looking for a way to rotate and then crop the largest rectangle containing content of the image. Is it possible with convert?
Edited by Mark Setchell...
So, if your original rectangle is a checkerboard created like this:
convert -size 512x512 pattern:checkerboard a.png
and you rotate it through 20 degrees like this
convert -background fuchsia -rotate 20 a.png b.png
you want the largest rectangle that fits on the checkerboard and contains no pink?
You can get an approximation of your expected result by using +repage and replacing -rotate with -distort ScaleRotateTranslate:
convert -background fuchsia -distort ScaleRotateTranslate 20 +repage a.png b.png
After creating the image as indicated:
convert -size 512x512 pattern:checkerboard a.png
This seems to do the work:
angle=20
ratio=`convert a.png -format \
"%[fx:aa=$angle*pi/180; min(w,h)/(w*abs(cos(aa))+h*abs(sin(aa)))]" \
info:`
crop="%[fx:floor(w*$ratio)]x%[fx:floor(h*$ratio)]"
crop="$crop+%[fx:ceil((w-w*$ratio)/2)]+%[fx:ceil((h-h*$ratio)/2)]"
convert a.png -set option:distort:viewport "$crop" \
+distort SRT $angle +repage rotate_internal.png
From here.

ImageMagick reorients iOS photos

I am currently converting images coming from mobiles apps, i.e. iOS, Android and WP.
I use image magick to resize the photos.
Here is my command line:
convert -resize 764x764 -strip -interlace Plane -quality 85% img1.jpg img2.jpg
It works fine for photos coming from Android and WP however, when I receive it from iOS, the photos are automatically rotated to landscape, even if they are portraits.
Any ideas?
Thank you.
Photo orientation can be defined by the images meta-data. Add the -auto-orient option to respect the EXIF data before removing it with -strip options.
convert img1.jpg -auto-orient \
-resize 764x764 \
-interlace Plane \
-strip \
-quality 85% \
img2.jpg
Warning from docs:
If the EXIF profile was previously stripped, the -auto-orient operator will do nothing.

Resources