Multiple page pdf to single png using ghostscript - imagemagick

I am trying to convert a multi page pdf to png using following command
gs -q -dNOPAUSE -dBATCH -sDEVICE=png256 -r600x600 -sOutputFile=out.png in.pdf
However it only converts the first page. I can pass a %d in out%d.png to get multiple pages, but I want a single png output. Is that possible ? I am aware of convert utility of imagemagick which does that (using gs as a delegate), but I want to do directly using gs.

I wasn't aware it was possible to have a PNG file which contains mutliple different images. As far as I am aware it is not possible to produce such a file with Ghostscript.

Related

Converting jpeg to bmp version 4 using imagemagick?

I can't seem to find a way to properly convert my images to bmp using imagemagick. Whenever I use this website with the current settings it works flawlessly in my program. https://online-converting.com/image/convert2bmp/
I've tried these commands:
convert disney.jpeg -format bmp:format=bmp4 out.bmp
convert disney.jpeg -define bmp:format=bmp4 -type truecolor -compress none out.bmp
Nothing seems to work. Not sure how to set up imagemagick so that it gives me back the same format as the website.
As for the program, you basically feed it the bmp file. It works when I convert with the website, but not with imagemagick.

ImageMagick argument to specify output format

I'm using ImageMagick programmatically to apply some user-defined transformations to an image. The script I'm using spawns a new process and runs ImageMagick with arguments similar to:
convert /tmp/source -resize 100x /tmp/transformed
And then it reads the transformed image back from /tmp/transformed. I'd like to add the option to convert the image to another image format, but from looking at the IM docs for a while, the only way I can see of doing that is to append the output destination with .<ext>, like this:
convert /tmp/source -resize 100x /tmp/transformed.png
Is there another way? The easiest way for me to do this with the pre-existing script is to supply an argument, but I can't find it. Something like:
convert /tmp/source -resize 100x -format png /tmp/transformed
Is this possible? Or am I stuck with having to append the extension to the output destination?
I'm not sure what your aversion is for appending a suffix, but another alternative to Fred's excellent suggestions is to use a "format specifier" prefix, which would leave your base filename unchanged - if that is what you are trying to achieve.
convert Image -resize 100x PNG:/tmp/transformed/Image
Substitute PNG: with GIF:, JPEG: etc to suit.
-format png is used in mogrify and not convert as I understand it. You need to specify the suffix for the input and the desired suffix for the output in the input and output filenames.
convert /tmp/source.suffx -resize 100x /tmp/transformed.png
assuming png is the desired output format.
Perhaps I misunderstand what you want. If so, please clarify. Are the suffixes in the source and transformed variables? If so, you can use IM to separate the source filename from its suffix using %t and %e in string formats. But for the output, you would have to parse that using your file system. See http://www.imagemagick.org/script/escape.php
Alternately, use mogrify which supports -format png
mogrify -format png -resize 100x *.suffix
That will take every file in the input directory with suffix .suffix and convert that to png. However, I would suggest you create a new directory to hold all your output images, since as it is, it will overwrite your input files. You would then need to add -path path2/newdirectory to the command above. see http://www.imagemagick.org/Usage/basics/#mogrify
What are the actual filenames associates with source and destination? Are these just variable for the real filenames?

How to get page no in tesseract while ocring multi tiff file

How can we get the page no in command line while ocring a multi tiff file. For eg -
tesseract myfile.tif output-page_no.txt
Here the output file should have the corresponding page no from the tiff file.
The hocr output option would produce page numbers. The text, however, can output page breaks, given the appropriate switches:
tesseract -c include_page_breaks=1 -c page_separator="[PAGE SEPRATOR]" 109359.tiff 109359
See this post.

ImageMagick: convert to keep same name for converted image

I am converting .psd to .png files inside folder with one. How to keep same name of every file in folder with different extension ?
For example I enter in folder images and then from terminal I execute
$ convert *.psd *.png
but it gives names to .png just numbers not the same as appropriate .psd image.
Use the -set and formatting options.
convert *.psd -set filename:base "%[basename]" "%[filename:base].png"
See "Long Form Attribute Percent Escapes" and "Filename Percent Escapes" docs.
Update
The mogrify utility that ships with imagemagick can also be used.
mogrify -format png *.psd
Note: Be careful with mogrify as the docs state...
This tool is similiar to convert except that the original image file is overwritten (unless you change the file suffix with the -format option) with any changes you request.
If you are on Linux, Unix or Mac OSX, you could use in a terminal window with Bash shell:
for i in *.psd; do
convert $i ${i/.psd/.png}
done
I deliberately do not advertise mogrify any more. It is too dangerous for every user who doesn't know it already, and who comes to this website to ask for help. mogrify is overwriting your original files in some cases (of course not when converting PSD->PNG)
Or, even simpler:
mogrify -format png *.psd
I like the top answer,
that being said, in later versions of ImageMagick, the command is
convert *.psd -set filename:basename "%[basename]" "%[filename:basename].png"
as also mentioned by #jan-glx and #jomel imperio

Convert EPS to PDF on the fly with pdflatex on the fly

I'm trying to include an EPS figure in a document that will be compiled using pdflatex. Of course, the picture can be converted to pdf using epstopdf (which comes with the MikTeX distribution). Is there any way to do this on the fly, that is, make pdflatex do the conversion?
I'm looking for such a solution because I want to set up an easy-to-learn environment for students. Ideally, the converted picture is placed in the directory that also contains the original .eps, and the .pdf is used if available.
The relevant answer in the TeX FAQ points to epstopdf.sty, included with Heiko Oberdiek's packages.
I would recommend using latex-mk which is a nice way to have a very simple Makefile for latex construction. Of course you can have eps file converted to pdf, or fig to eps, etc, during the build process.
Currently my Makefile look like that :
NAME=report
TEXSRCS=report.tex
BIBTEXSRCS=biblio.bib
USE_PDFLATEX=true
VIEWPDF=open # cause i'm on osx, gv for most unix
XFIGDIRS=img
## For osx users :
include /opt/local/share/latex-mk/latex.gmk
## For unix users :
#include /usr/share/latex-mk/latex.gmk
When I invoke make, the first thing it does is converting some .fig into .pdf files. I'm pretty sure it would do the same with eps files.
If you want to include one EPS figure in latex then you need to at first make the figure in EPS format if it is not in EPS format.Like if your figure is in .jpeg extension, then you need to make it .eps
Then you need to include it in the LaTex with using some code which is common in LaTex and then to make it in pdf format you need to use one small instruction that is \usepackage{epstopdf}
I was also facing this problem and found this post very helpful "How to Convert .eps to PDF in Latex ?"
Now i am able to include EPS figure in LaTex and also can convert it in PDF. I think you will also get help and all the details from the above link.Let me know if you face any further problem.

Resources