Crop & Rotate

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
QDeath
Posts: 6
Joined: 2018-06-25T04:12:46-07:00
Authentication code: 1152

Crop & Rotate

Post by QDeath »

I would like to take an anterior.jpg and specify the upper left x,y coordinate and the height & width of the selection I want to include and then rotate the final image. Example: anterior.jpg is 1536 x 2048: the part of the pic that I want has 427,364 as the upper left coordinate and then the new image has a resulting size of 738 x 1158 and rotate 15 degrees clockwise and have final image as anterior-crop.jpg.

Looking to do this for 300,000 images. Currently I have a CSV file with example line: "427","364","1158","738","0","2048","1536","25432\anterior"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop & Rotate

Post by fmw42 »

Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
QDeath
Posts: 6
Joined: 2018-06-25T04:12:46-07:00
Authentication code: 1152

Re: Crop & Rotate

Post by QDeath »

Sorry Windows!

I almost figured it out! Problem is I get the following error:
magick.exe: unable to open image '*-Modified.jpg': Invalid argument @ error/blob.c/OpenBlob/3457.

I want to save the new file with an appended as "-Modified.jpg" just not sure of the syntax. HELP!!


C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1000Lateral-Initial.jpg" -crop 978x1335+418+309 -rotate 0 *-Modified.jpg
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1001Frontal-Initial.jpg" -crop 971x1266+545+168 -rotate -4 *-Modified.jpg
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1002Frontal Smile-Initial.jpg" -crop 919x1197+505+122 -rotate 0 *-Modified.jpg
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1005Right Occlusion-Initial.jpg" -crop 599x381+560+845 -rotate -3 *-Modified.jpg
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1006Anterior Occlusion-Initial.jpg" -crop 748x477+810+453 -rotate 0 *-Modified.jpg
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1007Left Occlusion-Initial.jpg" -crop 534x340+465+889 -rotate 0 *-Modified.jpg
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1013Panoramic-Initial.jpg" -crop 1141x498+-58+0 -rotate 0 *-Modified.jpg
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\11995\1001Frontal-Initial.jpg" -crop 626x736+331+53 -rotate 0 *-Modified.jpg
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1004Lower Occlusal-Initial.jpg" -crop 753x602+790+402 -rotate 0 *-Modified.jpg
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1399Composite-Initial.jpg" -crop 640x512+0+0 -rotate 0 *-Modified.jpg
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Crop & Rotate

Post by GeeMack »

QDeath wrote: 2018-06-25T10:30:04-07:00I want to save the new file with an appended as "-Modified.jpg" just not sure of the syntax.
ImageMagick can hold the input file name as a variable to use as part of the output file name. Try something like this...

Code: Select all

magick input.jpg -set filename:f "%[t]-Modified" <do some other things here> "%[filename:f].jpg"
To use that in a BAT script you need to make the single percent signs "%" into doubles "%%".
QDeath
Posts: 6
Joined: 2018-06-25T04:12:46-07:00
Authentication code: 1152

Re: Crop & Rotate

Post by QDeath »

File shows %[t]-modified.jpg
QDeath
Posts: 6
Joined: 2018-06-25T04:12:46-07:00
Authentication code: 1152

Re: Crop & Rotate

Post by QDeath »

magick Anterior.jpg -set filename:f "%[t]-Modified" <do some other things here> "%[filename:f].jpg" -> This will crate Anterior-Modified.jpg?

Where are the docs for this?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Crop & Rotate

Post by snibgo »

Are you running this in a BAT file? If so, you must double the % to %%, as GeeMack says. See http://www.imagemagick.org/Usage/windows/
snibgo's IM pages: im.snibgo.com
QDeath
Posts: 6
Joined: 2018-06-25T04:12:46-07:00
Authentication code: 1152

Re: Crop & Rotate

Post by QDeath »

Still error:
C:\Users\Friedman\Desktop\Images>C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\11995\1001Frontal-Initial.jpg" -set filename:f "%[t]-Modified" -crop 626x736+331+53 -rotate 0 "%[filename:f].jpg"
magick.exe: unable to open image '.\11995\1001Frontal-Initial.jpg': No such file or directory @ error/blob.c/OpenBlob/3457.


C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1000Lateral-Initial.jpg" -set filename:f "%%[t]-Modified" -crop 978x1335+418+309 -rotate 0 "%%[filename:f].jpg"
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1001Frontal-Initial.jpg" -set filename:f "%%[t]-Modified" -crop 971x1266+545+168 -rotate -4 "%%[filename:f].jpg"
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1002Frontal Smile-Initial.jpg" -set filename:f "%%[t]-Modified" -crop 919x1197+505+122 -rotate 3 "%%[filename:f].jpg"
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1005Right Occlusion-Initial.jpg" -set filename:f "%%[t]-Modified" -crop 599x381+560+845 -rotate -3 "%%[filename:f].jpg"
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1006Anterior Occlusion-Initial.jpg" -set filename:f "%%[t]-Modified" -crop 748x477+810+453 -rotate 0 "%%[filename:f].jpg"
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1007Left Occlusion-Initial.jpg" -set filename:f "%%[t]-Modified" -crop 534x340+465+889 -rotate 0 "%%[filename:f].jpg"
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1013Panoramic-Initial.jpg" -set filename:f "%%[t]-Modified" -crop 1141x498+-58+0 -rotate 0 "%%[filename:f].jpg"
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\11995\1001Frontal-Initial.jpg" -set filename:f "%%[t]-Modified" -crop 626x736+331+53 -rotate 0 "%%[filename:f].jpg"
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1004Lower Occlusal-Initial.jpg" -set filename:f "%%[t]-Modified" -crop 753x602+790+402 -rotate 0 "%%[t]-Modified.jpg"
C:\Progra~1\ImageMagick-7.0.8-Q16\magick.exe ".\19995\1399Composite-Initial.jpg" -set filename:f "%%[t]-Modified" -crop 640x512+0+0 -rotate 0 "%%[filename:f].jpg"
QDeath
Posts: 6
Joined: 2018-06-25T04:12:46-07:00
Authentication code: 1152

Re: Crop & Rotate

Post by QDeath »

Oh no, my mistake. Thank you! Are there documentation on this type on input?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop & Rotate

Post by fmw42 »

Post Reply