PDF to Image conversion - Windows command line script - imagemagick

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.

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.

Convert image from one format to another sent to STDOUT

I'd like to convert an image from .jpg to .png. This works just fine:
convert input.jpg output.png
But, I'm trying to have my output go to STDOUT instead of a file, which the manual says to use "-".
I tried using:
convert input.jpg -.png
But it just creates a file called -.png.
Is it possible to convert an image from one format to another and have it go to STDOUT?
Yes, just use a command like this to convert a JPEG to a PNG on stdout:
magick input.jpg PNG:-
These specifiers work on input as well as output. So, if you have a TIFF on stdin and want a 32-bit RGBA PNG on stdout:
magick TIFF:- PNG32:-
You often need these specifiers to ensure a specific filetype when it is not explicitly given, or you want to use a different extension. So, say you have some CCD device that produces RGB data in a raw binary file called image.bin and you want ImageMagick to read it. You can tell ImageMagick the format without having to change the filename (to image.rgb) like this:
magick -size WxH RGB:image.bin result.png
The possible formats are documented here.
The king of all of these formats is MIFF which is guaranteed to be able to hold any and all things you might throw at it, including floating-point values, transparency, masks, concatenated streams... so if you need a format to pass between ImageMagick commands, MIFF is a good option. An example, just to demonstrate because it is not optimal, might to be to concatenate two images from 2 separate ImageMagick commands into a third command that makes an animated GIF:
{ magick -size 100x60 xc:red miff:- ; magick -size 100x60 xc:blue miff:- ; } | magick -delay 80 miff:- result.gif

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.

pink tif file made from ImageMagick

I am trying to send a tiff file through fax machine.
This file seems fine with image viewer and paint, but
my boss told me that while trying to send the tif file using fax program,
he's getting pink all over his background instead of white..
and 40 kb of tif file bumps up to 600kb while trying to send the tif file..
And I used ImageMagick converting from PDF to Tiff, and the command line I used was
"C:/Program Files/ImageMagick-7.0.3-Q16/convert.exe" -density 200 -resize 1728x2291 -monochrome -compress group4 D://fax_files/201612/20161208155410.pdf D://fax_files/201612/example/1.tif
the pink image is here..
Did I make any mistakes on using ImageMagick or are there any issues that cause the problem?
If you know any, please help me out..
Thank you in advance..
I believe that to fax a tiff, it has to be binary (black/white), not color and needs to be compressed with group 4 compression.
With PDF files you need to set the density and units before reading the input and all the other arguments afterwards.
So
convert -density XXX -unit YYY image.pdf -resize ZZZ -monochrome -compress group4 image.tif

imagemagick issue converting pdf form and overlaying pages

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. ;-)

Resources