Return to Snippet

Revision: 44833
at April 19, 2011 21:01 by mld15


Initial Code
@echo off

rem 1. Download & install ImageMagick from http://www.imagemagick.org/script/binary-releases.php#windows. 
rem This is a command line utility to work with images. No ads, toolbars and other crap. It is freeware and open source.
rem You need file named ImageMagick-<version number>-windows-static.exe
rem 
rem 2. Create new file conv.bat with this snippet inside in a folder with images.
rem This will automatically trim all images in this folder and all its subfolders.

rem Settings :

rem Images extension
rem jp*g will match both .jpg's and .jpeg's
set extension=jp*g

rem How much tolerance when matching color in percents
rem Larger tolerance = broader color range is regarded same and trimmed
rem Zero will mach only one exact color, use it for perfectly clean images in lossless formats (png, tif etc)
rem Use small value for clean images in jpegs, 1%%-5%% is a good start
set tolerance=4%%

rem More info on parameters - see http://www.imagemagick.org/Usage/crop/#trim

for /R %%i in (*.%extension%) do ( 
	echo Trimming %%i
	convert "%%i" -fuzz "%tolerance%" -trim +repage "%%i" 
)

Initial URL

                                

Initial Description
Worked great for trimming margins in scanned comics and books, much easier and faster than complex photoshop scripts. :)

1. Download & install ImageMagick from http://www.imagemagick.org/script/binary-releases.php#windows. 
This is a command line utility to work with images. No ads, toolbars and other crap. It is freeware and open source.
You need file named ImageMagick-<version>-windows-static.exe

2. Create new file conv.bat with this snippet inside in a folder with images and launch it.
This will automatically trim all images in this folder and all its subfolders.

3. Optionally you can set different extension if you need to crop something other than jpegs's, and increase color tolerance - to detect larger borders. There are also other settings, like cropping only borders of certain color - you can read full documentation at http://www.imagemagick.org/Usage/crop/#trim .

It will also work on Linux and Mac since ImageMagick is a crossplatform tool, but you will have to modify .bat file to be compatible with Bash syntax.

Initial Title
Automatically trim/remove white/black/any borders from images

Initial Tags

                                

Initial Language
DOS Batch