Re: How to crop margin in imagemagick?
Posted: 2012-02-11T07:49:27-07:00
The first command from you still does not work. I gives still the same errors that "No such file or directory"
At this point this is worse than the command that I posted here yesterday. My command converted cca 5 files. Your command converted only one file.
If you would like to test the files that I try to convert, they are placed here:
http://www.aircharts.org/enroute/
I try to convert files from Austria, Belgium, Croatia, Cyprus, Czech_republic, Denmark, Estonia... Yet I did not try more files to convert because the Estonia was the last file I tried without success.
Once again the code of mine, that works for at least 5 files:
Code: Select all
If you're gonna use this code in batch file, you must use double % instead sinle
which is used in command line CMD!
D:\Europe>for /R %F in (*.pdf) do "c:\program files\ImageMagick-
6.7.5-Q8\convert.exe" -density 400 -colorspace RGB "%F" -background white -alpha
remove -shave 30%x30% -quality 34% "%~dF%~pF%~nF.jpg"
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Austria\lower.pdf" -background white
-alpha remove -shave 30%x30% -quality 34% "D:\Europe\Austria\lower.jpg"
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Austria\upper.pdf" -background white
-alpha remove -shave 30%x30% -quality 34% "D:\Europe\Austria\upper.jpg"
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Belgium\lower.pdf" -background white
-alpha remove -shave 30%x30% -quality 34% "D:\Europe\Belgium\lower.jpg" -de
nsity 400 -colorspace RGB "D:\Europe\Austria\upper.pdf" -background white -
alpha remove -shave 30%x30% -quality 34% "D:\Europe\Austria\upper.jpg"
convert.exe: unable to open image `D:\Europe\Belgium\lower.jpg': No such fi
le or directory @ error/blob.c/OpenBlob/2614.
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Belgium\upper.pdf" -background white
-alpha remove -shave 30%x30% -quality 34% "D:\Europe\Belgium\upper.jpg" -de
nsity 400 -colorspace RGB "D:\Europe\Austria\upper.pdf" -background white -
alpha remove -shave 30%x30% -quality 34% "D:\Europe\Austria\upper.jpg"
convert.exe: unable to open image `D:\Europe\Belgium\upper.jpg': No such fi
le or directory @ error/blob.c/OpenBlob/2614.
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Belgium\upper_enr3.pdf" -background w
hite -alpha remove -shave 30%x30% -quality 34% "D:\Europe\Belgium\upper_enr
3.jpg" -density 400 -colorspace RGB "D:\Europe\Austria\upper.pdf" -backgrou
nd white -alpha remove -shave 30%x30% -quality 34% "D:\Europe\Austria\upper
.jpg"
convert.exe: unable to open image `D:\Europe\Belgium\upper_enr3.jpg': No su
ch file or directory @ error/blob.c/OpenBlob/2614.
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Croatia_(Chorvatsko)\lower.pdf" -back
ground white -alpha remove -shave 30%x30% -quality 34% "D:\Europe\Croatia_(
Chorvatsko)\lower.jpg" -density 400 -colorspace RGB "D:\Europe\Austria\uppe
r.pdf" -background white -alpha remove -shave 30%x30% -quality 34% "D:\MAPY\Euro
pe\Austria\upper.jpg"
convert.exe: unable to open image `D:\Europe\Croatia_(Chorvatsko)\lower.jpg
': No such file or directory @ error/blob.c/OpenBlob/2614.
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Croatia_(Chorvatsko)\upper.pdf" -back
ground white -alpha remove -shave 30%x30% -quality 34% "D:\Europe\Croatia_(
Chorvatsko)\upper.jpg" -density 400 -colorspace RGB "D:\Europe\Austria\uppe
r.pdf" -background white -alpha remove -shave 30%x30% -quality 34% "D:\MAPY\Euro
pe\Austria\upper.jpg"
convert.exe: unable to open image `D:\Europe\Croatia_(Chorvatsko)\upper.jpg
': No such file or directory @ error/blob.c/OpenBlob/2614.
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Cyprus\enroute.pdf" -background white
-alpha remove -shave 30%x30% -quality 34% "D:\Europe\Cyprus\enroute.jpg" -
density 400 -colorspace RGB "D:\Europe\Austria\upper.pdf" -background white
-alpha remove -shave 30%x30% -quality 34% "D:\Europe\Austria\upper.jpg"
**** Warning: File has insufficient data for an image.
libpng error: Write Error
Error: /VMerror in --showpage--
VM status: 3 935695 2253216
Current allocation mode is local
Last OS error: 28
GPL Ghostscript 9.04: Unrecoverable error, exit code 1
convert.exe: `%s': %s "c:/program files/GhostScript9.04/bin/gswin32c.
exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPS
Crop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGra
phicsAlphaBits=4 "-r400x400" -g67533x50656 "-sOutputFile=C:/DOCUME~1/ADMINI~1/L
OCALS~1/Temp/magick-_Lzx5dSg-12275968" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/mag
ick-oEPfSZJn" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-F_EINF75" @ error/pdf
.c/InvokePDFDelegate/199.
convert.exe: Postscript delegate failed `D:\Europe\Cyprus\enroute.pdf': No
such file or directory @ error/pdf.c/ReadPDFImage/667.
convert.exe: unable to open image `D:\Europe\Cyprus\enroute.jpg': No such f
ile or directory @ error/blob.c/OpenBlob/2614.
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Czech_republic\lower.pdf" -background
white -alpha remove -shave 30%x30% -quality 34% "D:\Europe\Czech_republic\
lower.jpg" -density 400 -colorspace RGB "D:\Europe\Austria\upper.pdf" -back
ground white -alpha remove -shave 30%x30% -quality 34% "D:\Europe\Austria\u
pper.jpg"
convert.exe: unable to open image `D:\Europe\Czech_republic\lower.jpg': No
such file or directory @ error/blob.c/OpenBlob/2614.
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Czech_republic\upper.pdf" -background
white -alpha remove -shave 30%x30% -quality 34% "D:\Europe\Czech_republic\
upper.jpg" -density 400 -colorspace RGB "D:\Europe\Austria\upper.pdf" -back
ground white -alpha remove -shave 30%x30% -quality 34% "D:\Europe\Austria\u
pper.jpg"
**** Warning: xref subsection header has extra characters.
**** Warning: An error occurred while reading an XREF table.
**** The file has been damaged. This may have been caused
**** by a problem while converting or transfering the file.
**** Ghostscript will attempt to recover the data.
**** Warning: There are objects with matching object and generation
**** numbers. The accuracy of the resulting image is unknown.
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Acrobat Distiller 6.0 (Windows) <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
convert.exe: unable to open image `D:\Europe\Czech_republic\upper.jpg': No
such file or directory @ error/blob.c/OpenBlob/2614.
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Denmark\lower.pdf" -background white
-alpha remove -shave 30%x30% -quality 34% "D:\Europe\Denmark\lower.jpg" -de
nsity 400 -colorspace RGB "D:\Europe\Austria\upper.pdf" -background white -
alpha remove -shave 30%x30% -quality 34% "D:\Europe\Austria\upper.jpg"
convert.exe: unable to open image `D:\Europe\Denmark\lower.jpg': No such fi
le or directory @ error/blob.c/OpenBlob/2614.
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Denmark\upper.pdf" -background white
-alpha remove -shave 30%x30% -quality 34% "D:\Europe\Denmark\upper.jpg" -de
nsity 400 -colorspace RGB "D:\Europe\Austria\upper.pdf" -background white -
alpha remove -shave 30%x30% -quality 34% "D:\Europe\Austria\upper.jpg"
convert.exe: unable to open image `D:\Europe\Denmark\upper.jpg': No such fi
le or directory @ error/blob.c/OpenBlob/2614.
D:\Europe>"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -d
ensity 400 -colorspace RGB "D:\Europe\Estonia\enroute.pdf" -background whit
e -alpha remove -shave 30%x30% -quality 34% "D:\Europe\Estonia\enroute.jpg"
-density 400 -colorspace RGB "D:\Europe\Austria\upper.pdf" -background whi
te -alpha remove -shave 30%x30% -quality 34% "D:\Europe\Austria\upper.jpg"
**** Warning: File has unbalanced q/Q operators (too many q's)
**** This file had errors that were repaired or ignored.
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
If you would like to test the files that I try to convert, they are placed here:
http://www.aircharts.org/enroute/
I try to convert files from Austria, Belgium, Croatia, Cyprus, Czech_republic, Denmark, Estonia... Yet I did not try more files to convert because the Estonia was the last file I tried without success.
Once again the code of mine, that works for at least 5 files:
Code: Select all
for /r %%F in (*.pdf) do ^
"c:\program files\ImageMagick-6.7.5-Q8\convert.exe" -density 400 -shave 30%%x30%% -quality 34%% %%F %%F.jpg