imagemagick issue converting pdf form and overlaying pages - imagemagick

I'm using imagemagik to convert pdf's ( and other types ) to jpg.
Here is my command
"D:\\bc_458.pdf -resize 100x100 -flatten -quality 92 -background white D:\\tn_abc_458.jpg"
I am having 2 issues with this.
1) it doesn't work with pdf's that contains forms.
2) it is overlaying pages on top of each other. For example "bc_458.pdf" has 3 pages. tn_abc_458.jpg is created with all 3 layers overlaying each other.

ImageMagick is a (pixel) images processing software.
It doesn't process PDF input files itself -- it uses Ghostscript as a 'delegate' to convert PDF pages to pixel images first.
So, which version of Ghostscript have you installed? On Windows, run
gswin32c.exe -v
or
gswin64c.exe -v
on Mac OS X, Linux or Unix run:
gs -v
to find out.
What exactly are you problems with the PDF forms? 'It doesn't work with forms' doesn't tell me much...
The problem of overlaying the 3 page images over each other you can easily overcome: simply drop the -flatten part of the commandline (because that's what's responsible for the effect you observe). Furthermore, you could specify %04d as part of the output filename in order to have control of where ImageMagick puts the page number:
convert \
bc_458.pdf \
-resize 100x100 \
-quality 92 \
-background white \
page_%04d_bc_458.jpg"
I'm pretty sure that the command you quoted doesn't even do what you say it does: you forgot to put the convert command to the front of the line. ;-)

Related

ImageMagick v7 conversion of 8bpp images

On Windows 10, I need to crop and resize whole folders of images.
Following the documentation and some answers here i've built this batch:
magick mogrify -path ./cropped -crop 1300x1940+85+130 +repage -resize "800x800^" *.jpg
It mostly works, but when a folder has mixed image formats (some are 24bpp, some are 8bpp, grayscale) this batch skips all the 8bpp ones.
How can i change my command so it accepts and modify every image, no matter what?
Note: i used mogrify as i understand it is needed to process a whole folder and save the result in another one, but i'm unsure it is necessary.

How can I merge or convert multiple ImageMagick command into one single command

a) I have multiple ImageMagick commands and I need to convert those multiple commands into one. I tried it by putting all the parameters in single command, but somehow it was not working and I had to discard it.
magick -density 300 cheque25.jpg -depth 8 -strip -background white -alpha off cheque25.png
magick convert cheque25.png -resize 150% res_cheque25.png
magick convert -brightness-contrast 10x30 res_cheque25.png b_res_cheque25.png
magick convert b_res_cheque25.png -threshold 45% bin_res_cheque25.png
b) Also, is there any chance that merged commands will give any different output than multiple single command?
Your ImageMagick syntax is not correct in several ways. In ImageMagick 7, you replace convert with magick. Also your input should come right after magick. ImageMagick 6 is forgiving of syntax, but ImageMagick 7 is not. See http://imagemagick.org/script/porting.php#cli
Try the following:
magick cheque25.jpg -depth 8 -strip -alpha off -background white -resize 150% -brightness-contrast 10x30 -threshold 45% -density 300 bin_res_cheque25.png
If that does not work, then provide a link to your input image, so others can test your commands and verify against mine.
The combined commands should give the same as a properly formatted set of commands, provided no syntax errors are present and settings are reset where needed and parenthesis processing is properly used when and where needed. I make no guarantees, since your set of commands is not using proper syntax.

Imagemagick cropping thumbnail command line

I have an adult website and I want to remove watermarks by Imagemagick commands.
I would like to show you the thing I want as visuals.
Original image comes with 278x140 (I can change these) > Here
What I want is something like this > This
In the default settings of ImageMagick in my website script, that command line is default;
-modulate 110,102,100 -sharpen 1x1 -enhance
and I added next to it -gravity center -crop wxh+0+0 (I filled width and height in the code) but didn't work.
I just want my imagemagick command to crop a smaller square from the middle.
This is my settings in the admin script of the website.
After that, this is my screen of thumbnails in editing content
When I click "regenarate", it doesn't give error, it says success;
But nothing changes in the editing content screen after that. Still same thumbnails.
Using Imagemagick 6.9.9.40 Q16 Mac OSX, I ran your command replacing 1x1 with 0x1 and it works just fine. I took your command from your code JPGs.
Input:
mogrify -modulate 110,102,100 -sharpen 0x1 -enhance -gravity center -crop 150x100+0+0 +repage OX5XX.jpg
I am not sure why you are using mogrify, if you are convert only one image at a time in your loop. You could just use convert as
convert OX5XX.jpg -modulate 110,102,100 -sharpen 0x1 -enhance -gravity center -crop 150x100+0+0 +repage OX5XX.jpg
I would suggest you make a simple PHP command to just run the same as above and see if that works. If it does, then the problem is in your other code and perhaps your usage of FFMPEG. If it does not work, then it could be a bug in your version of Imagemagick.
You can find out the version of Imagemagick by
<?php
exec("convert -version",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
If that fails, then find the full path to convert via
<?php
echo "<pre>";
system("type -a convert");
echo "</pre>";
?>
Without a complete command it's hard to say exactly where the error might be, but with ImageMagick the first thing I'd try is the same command using "-extent wxh" instead of "-crop wxh+0+0" for this.

Imagemagick convert and compose batch of files

I am trying to make a fast convert of a batch of files like this:
convert ./src/*.png -set filename: '%t' -gravity West -draw 'image over 0,0 424,600 "./panel.png"' ./dest/%[filename:].png
which is pretty similar to COMPOSITE:
convert ./src/*.png ./panel.png -set filename: '%t' -gravity +0+0 -composite ./dest/%[filename:].png
except the last one is not working and just making one first crappy-looking file.
Looks like it's bug?
Does anybody know how to make it more correct with -composite?
for|awk|ls|find for each file in shell is not acceptable - because that is slower than the first example.
Read in the list of files,
set their output filenames,
include the IM special image placeholder "null:",
read in your overlay image,
optionally, set the geometry,
and composite that overlay onto all the other images with "-layers composite".
That null: separates the original input file list from the overlay image so ImageMagick knows where in the stack you want to start doing the composite.
Try something like this (one step per line for readability):
convert ./src/*.png \
-set filename: '%t' \
null: \
./panel.png \
-layers composite ./dest/%[filename:].png
You could use Imagemagick mogrify command. See http://www.imagemagick.org/Usage/basics/#mogrify and http://www.imagemagick.org/Usage/basics/#mogrify_compose
cd to input directory
mogrify -format png -path ./dest -gravity West -draw 'image over 0,0 424,600 "./panel.png"' *.png
Looks like it's bug?
Not a bug. Your second command is telling ImageMagick to consume all files matched into an image stack, and composite it as one.
You can attempt the same solution with the mogrify utility, but I believe it would be way simpler if you expand the bash script with a single for loop.
for f in $(ls src/*.png)
do
dest=$(basename $f);
convert "$f" ./panel.png -gravity West -composite "./dest/$dest"
done

PDF to Image conversion - Windows command line script

I have to write a windows command line shell script to convert pdf to Images.
Sample command:
convert.exe -density 300x300 -resize 3508x <file>.pdf -units PixelsPerInch -profile srgb.icc <FILE>.jpg
This command works fine for pdfs with NON-White background but goes wrong with pdfs with WHITE background. Any idea how I can give a command that works for both?
Plus
1) If the PDF is converted to .png ( as opposed to .jpg) it works. Any idea why?
This might be helpful, Save pdf to jpeg using c#.
Also have a look here.

Resources