how do I rotate image and strip meta using convert?

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
newbie_user
Posts: 6
Joined: 2019-01-03T12:18:07-07:00
Authentication code: 1152

how do I rotate image and strip meta using convert?

Post by newbie_user »

I am using convert to create a new image, rotate and striping meta info but it fails to rotate when using -strip. I assume because strip removed the EXIF:orientation. So


magick convert "IMG_20180830_110737.jpg" -rotate 180 -strip "new_IMG_20180830_110737-4.jpg" results in image not being rotated and removing -strip results in rotated image with meta info.

how do I accomplish both?
using Version: ImageMagick 7.0.7-31 Q16 x64 2018-05-07
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how do I rotate image and strip meta using convert?

Post by fmw42 »

There is no reason that -rotate 180 would not work. You already have -strip after it, which is proper. However, your viewer may be seeing the EXIF orientation and automatically correcting it. But then your rotate and strip and get back to the original orientation.

If the EXIF data has orientation information, then just use -auto-orient.

For IM 7, use magick, not magick convert and not convert.

Code: Select all

magick "IMG_20180830_110737.jpg" -auto-orient -strip "new_IMG_20180830_110737-4.jpg"
Mom4321
Posts: 1
Joined: 2019-01-03T21:18:29-07:00
Authentication code: 1152

Re: how do I rotate image and strip meta using convert?

Post by Mom4321 »

You could use the auto-orient option of convert to do this. Also Don't forget you can use mogrify instead of convert if you want to replace the existing file (in-place), which is useful when you want to do a directory full.
newbie_user
Posts: 6
Joined: 2019-01-03T12:18:07-07:00
Authentication code: 1152

Re: how do I rotate image and strip meta using convert?

Post by newbie_user »

fmw42 wrote: 2019-01-03T15:43:11-07:00 There is no reason that -rotate 180 would not work. You already have -strip after it, which is proper. However, your viewer may be seeing the EXIF orientation and automatically correcting it. But then your rotate and strip and get back to the original orientation.

If the EXIF data has orientation information, then just use -auto-orient.

For IM 7, use magick, not magick convert and not convert.

Code: Select all

magick "IMG_20180830_110737.jpg" -auto-orient -strip "new_IMG_20180830_110737-4.jpg"
So I tried your code and it doesn't rotate, image still upside down. Tried this and didn't work either.

Code: Select all

magick "IMG_20180830_110737.jpg" -rotate 180 -strip "new_IMG_20180830_110737-4.jpg"
remove -strip and -rotate works, -auto-orient still doesn't. Using irfanviewer 4.51 and windows thumbnails show it upside down as well.

Odd thing is on SOME when I used only -strip the image rotated automagically but only on some. Go figure!

If I use windows explorer to rotate the image, I notice EXIF orientation is added, I then use -strip and image is upside down again.
If I use irfanviewer to rotate no exif data is added and image stays rotated.
Last edited by newbie_user on 2019-01-03T23:53:00-07:00, edited 1 time in total.
newbie_user
Posts: 6
Joined: 2019-01-03T12:18:07-07:00
Authentication code: 1152

Re: how do I rotate image and strip meta using convert?

Post by newbie_user »

Mom4321 wrote: 2019-01-03T21:23:56-07:00 You could use the auto-orient option of convert to do this. Also Don't forget you can use mogrify instead of convert if you want to replace the existing file (in-place), which is useful when you want to do a directory full.
mogrify isn't and option as I have to keep the original files unmodified and I cant get -auto-orient to work at all. I'm open to other ideas thou.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how do I rotate image and strip meta using convert?

Post by fmw42 »

Post one of your images that seems to have issues. Perhaps there is no EXIF orientation in the file.
newbie_user
Posts: 6
Joined: 2019-01-03T12:18:07-07:00
Authentication code: 1152

Re: how do I rotate image and strip meta using convert?

Post by newbie_user »

both images are orientated with EXIF:Bottom Right and taken with same camera.
irfran and windows (thumbnail) show same orientation (on originals) and varies on modified


strip flips correctly but rotate strip does not -
Image 1 - Originally orients upside down on my PC
https://imagebin.ca/v/4SNDUUUchVf3
strips and flips

Code: Select all

magick image1.jpg -strip newimage1-1.jpg

strips and no flip

Code: Select all

magick image1.jpg -rotate 180 -strip newimage1-2.jpg

does not work (does do something to Image 2)

Code: Select all

magick image1.jpg -auto-orient newimage1-3.jpg



Already orientated correctly so strip should just remove the EXIF but -strip flips the image upside down.
Image 2 - Original orients correctly on my PC
https://imagebin.ca/v/4SNEsfAU7cve

strips and flips (wrong)

Code: Select all

magick image2.jpg -strip newimage2-1.jpg

strips and flips

Code: Select all

magick image2.jpg -rotate 180 -strip newimage2-2.jpg

works (windows thumbnail is upside down, exif shows top left now)

Code: Select all

magick image2.jpg -auto-orient newimage2-3.jpg


Thanks for the help, very appreciated
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how do I rotate image and strip meta using convert?

Post by fmw42 »

Both these work fine for me on IM 7.0.8.23 Q16 Mac OSX

Code: Select all

magick image.jpg -auto-orient image2.jpg

Code: Select all

magick image.jpg -auto-orient -strip image3.jpg
Thumbnails look correct on my Mac.
newbie_user
Posts: 6
Joined: 2019-01-03T12:18:07-07:00
Authentication code: 1152

Re: how do I rotate image and strip meta using convert?

Post by newbie_user »

I installed Version: ImageMagick 7.0.8-23 Q16 x64 2019-01-02 (dll) on clean windows 10 pro and still does not work.
I downloaded image1 and image2 from above and noticed imagebin has image 1 right side up and image 2 upside down.
This is opposite to what PC shows. Verified the both downloaded images are still set to bottom right as well.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how do I rotate image and strip meta using convert?

Post by fmw42 »

Yes, for me your first image does not work properly with -auto-orient. But the second image does work fine for me on IM 7.0.8.23 Q16 Mac OSX. I do verify that both images have EXIF:orientation of 3.

I am not sure what is wrong. A guess would be something odd in your file.
Post Reply