Page 1 of 1

Rotating, merging and cropping batch of images

Posted: 2017-03-16T07:16:20-07:00
by Koozer
Hi there,

I have the need to rotate pairs of images, stitch them horizontally and then crop to a certain size. Currently I'm doing this one step at a time and producing lots of excess images as my attempts to pipe outputs is failing me. I'm trying to do something like the following in Powershell:

magick (convert "d:\a folder with spaces\01022017083759_01.jpg" -rotate 270 -quality 100 "d:\a folder with spaces\rotated\01022017083759_01_rot270.jpg") (convert "d:\a folder with spaces\01022017083759_02.jpg" -rotate 90 -quality 100 "d:\a folder with spaces\rotated\01022017083759_02_rot90.jpg") "d:\a folder with spaces\rotated\01022017083759_02_rot90.jpg" "d:\a folder with spaces\rotated\01022017083759_01_rot270.jpg" +append miff:- | magick - -crop 7633x5767+1975.5+1460.5 +repage "d:\a folder with spaces\cropped\01022017083759_cropped.jpg"

This command runs, but seems to just go forever, hogging CPU resources. Each individual command works fine on its own, outputting to jpegs. What am I doing wrong?

Re: Rotating, merging and cropping batch of images

Posted: 2017-03-16T07:47:06-07:00
by snibgo
Do you want to keep the intermediate files? Why are they JPG format? I don't see why you are piping at all. There is only one image, so that can be cropped in the same command as the append.

If you don't need the intermediates, then this does the job. For clarity, I simplify the filenames.

Code: Select all

magick ( 9_01.jpg -rotate 270 ) ( 9_02.jpg -rotate 90 ) +append -crop 7633x5767+1975.5+1460.5 +repage out.tiff
If you do want to keep the intermediates, insert "+write temp_rotX.jpg" at any places you want within that command.

Re: Rotating, merging and cropping batch of images

Posted: 2017-03-16T08:03:25-07:00
by Koozer
Thanks for the suggestion, but I get an error on the rotation when I try that:

Code: Select all

You must provide a value expression on the right-hand side of the '-' operator.
At line:1 char:
+ magick ( "01022017083759_01.jpg" - <<<< rotate 270 ) ( "01022017083759_02.jpg" -rotate 90 ) +append
 -crop 7633x5767+1975.5+1460.5 +repage "cropped\01022017083759_cropped.jpg"
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression
I am not interested in the intermediary images, I only create them at the moment as it's the only way I can get the process to work!

Re: Rotating, merging and cropping batch of images

Posted: 2017-03-16T08:21:01-07:00
by snibgo
The version I showed is for the Windows command line. Sorry, I don't use Powershell, and don't know how to write it in a way that Powershell understands, or what escapes Powershell might need for the parentheses etc.

Re: Rotating, merging and cropping batch of images

Posted: 2017-03-16T08:57:19-07:00
by Koozer
Ah so it's a Powershell issue not Imagemagick? That narrows it down at least, thanks!

Re: Rotating, merging and cropping batch of images

Posted: 2017-03-16T09:05:05-07:00
by snibgo
Yes, the error messages are coming from Powershell. Sorry, I can't help with that. When you get it working, I encourage you to post it here, to help other people who use IM in Powershell.

Re: Rotating, merging and cropping batch of images

Posted: 2017-03-18T05:53:00-07:00
by Koozer
So Powershell was reading the brackets as special characters rather than literals, which was easy enough to solve by escaping with `. The bit that stumped me was that it still didn't work for some mysterious reason. Turns out Imagemagick doesn't like it if your brackets don't have spaces around them...

The following ridiculously simple line now works perfectly in Powershell:

Code: Select all

magick 'img1.png' -rotate 90 `( 'img2.png' -rotate 270 `) +append -crop 124x62+62+31 +repage 'out.png'