MacResource
Batch edit photos, shave off 20 pixels off the top - Printable Version

+- MacResource (https://forums.macresource.com)
+-- Forum: My Category (https://forums.macresource.com/forumdisplay.php?fid=1)
+--- Forum: Tips and Deals (https://forums.macresource.com/forumdisplay.php?fid=3)
+--- Thread: Batch edit photos, shave off 20 pixels off the top (/showthread.php?tid=291012)



Batch edit photos, shave off 20 pixels off the top - davemchine - 10-15-2024

I have hundreds of png files that need the top 20 pixels shaved off. Is there a way to do this by batch? I’m reasonably good at terminal or I have graphic converter. Thanks.


Re: Batch edit photos, shave off 20 pixels off the top - special - 10-16-2024

Try ChatGPT to write a simple Python code.


Re: Batch edit photos, shave off 20 pixels off the top - davemchine - 10-16-2024

I ended up using the command
mogrify -crop 1280x1024+0+0 *.png
which I found at https://superuser.com/questions/1161340/how-to-crop-an-image-using-imagemagick-from-the-command-line .

Then I wrote a simple script to do the job for me as it is a reoccurring situation.

#!/bin/bash
while true; do
echo
This will modify the files. Hope you have a backup!
read -p
Are you in directory with image files?
yn
case $yn in
[Yy]* ) echo
;
read -p
What extension do the image files have?
extention
identify *.
$extention
echo
**Now you know the resolution of the files in dir

echo
Now set the width and length
echo
For Architectural Digest use 2064 and 2602
echo
read -p
What width from left border is desired?
width
read -p
What length is desired?
length
echo
echo
Now set the offsets
echo
For Architectural Digest use 0 and 150
echo
read -p
What offset from left is desired?
xoffset
read -p
What offset from top is desired?
yoffset
echo
echo
Modifying original files, hope you made a backup...
mogrify -verbose -crop
$width
x
$length
+
$xoffset
+
$yoffset
*.
$extention
break;;
[Nn]* ) echo
Please place files into folder and run again.
; exit;;
* ) echo
Please answer yes or no.
;;
esac
done