I downloaded ImageMagick so I could batch process folders of images at work, cropping them to size and then slicing them into 12 equal pieces. I can do each task individually, but I'd rather execute it all in one line using STDIN and STDOUT. However, even after looking through answers here and the documentation on the website, I'm not any closer to making it work.
I'm working in Windows Powershell. Here's what I've tried, working with a single image:
convert -crop '5072x3552+87+0' image.jpg jpg:- | convert -crop '1268x1184' - jpg: - | convert -crop '1268x1030+0+0' - C:\folder1\folder2\folder3\square.jpg
This gives me a series of errors:
convert.exe: no decode delegate for this image format `' @ error/constitute.c/ReadImage/508.
convert.exe: no images defined `jpg:-' @ error/convert.c/ConvertImageCommand/3253.
convert.exe: no decode delegate for this image format `' @ error/constitute.c/ReadImage/508.
convert.exe: no images defined `C:\users\lmcane\desktop\imagem\test\leaf.jpg' @ error/convert.c/ConvertImageCommand/3253
I'm using ImageMagick 7.0.2 on Windows 7. Windows PowerShell is opened as administrator.
Additional guidance on formatting STDIN and STDOUT in imagemagick would be welcome.
Any help appreciated.
I would try doing the first trim of the edges using -fuzz
(to allow for small differences in the border colour) and -trim
. That gets you this:
convert grid.png -fuzz 30% -trim trimmed.png
Then, I would tile to 4x3 and repage the images so they forget their positions in the original image:
convert trimmed.png -crop 4x3@ +repage step2.png
Now crop off the tops, bottoms and sides and save the individual 12 frames:
convert step2.png -crop 130x100+20+20 f-%02d.png
Now you can trim the excess, using a slightly different fuzz as there seems to be less variation here than in the outer edge of the original image. And, I have also put all the commands together in one that does all the steps for all 12 images in one go:
convert grid.png -fuzz 30% -trim -crop 4x3@ +repage -crop 130x100+20+20 -fuzz 5% -trim f-%02d.png
You may have to play with the fuzz factor for other images, but you should see how it works now.