ImageMagick error with rails - ruby-on-rails

I use MiniMagick (A ruby wrapper for ImageMagick) with rails-4.2 (ruby 2.2.0) on a linux server.
I generate images via ttf. Each image has from 1 to 10 layers I then merged to create an image. I get an error which I can not find the solution.
MiniMagick::Error (`convert -background none -fill #000000 -font ttf/SELIS006N.ttf -pointsize 300 label: S public/pictogram_images/873-layer-2.png` failed with error:
convert.im6: invalid geometry `+3.35542e+07+300.5' # error/geometry.c/ParsePageGeometry/1407.
convert.im6: unable to clone cache `/tmp/magick-1r313oY0': No space left on device # error/cache.c/CloneDiskToDiskPixelCache/852.
convert.im6: Image width exceeds user limit in IHDR `public/pictogram_images/873-layer-2.png' # warning/png.c/MagickPNGWarningHandler/1754.
convert.im6: Invalid IHDR data `public/pictogram_images/873-layer-2.png' # error/png.c/MagickPNGErrorHandler/1728.
):
SELIS006N.ttf is my ttf files, the character is "S" and the image path is public/pictogram_images/873-layer-2.png
I test the character with the same .ttf character and it's a completely normal without particuliarity.

Part of the error you received is this line:
unable to clone cache `/tmp/magick-1r313oY0': No space left on device
It seems that the filesystem containing your /tmp directory is just full.
If this doesn't seem to actually be the case and the image you try to convert has a reasonable file size, this might also be an artefact of a corrupt source file. ImageMagick might try to expand compressed parts of the file until it runs out of space and fails.

Related

Contrast feature of ImageMagick convert

I just want to use the convert command in a way, so that the pictures get in colorspace gray, negated and with a higher contrast.
The colorspace and negation are not a problem, but the contrast is one. I use the following bash script:
for i in *
do
echo $i
convert $i -colorspace gray gray/$i
convert gray/$1 -contrast -contrast contrasted/$1
convert contrasted/$i -negate negated/$i
done
I moved the contrast command in every possible position, but there always comes the following error:
convert-im6.q16: no decode delegate for this image format `' # error/constitute.c/ReadImage/504.
convert-im6.q16: no images defined `contrasted/' # error/convert.c/ConvertImageCommand/3258.
convert-im6.q16: unable to open image `contrasted/s5_rechts_abgeschnitten.png': Datei oder Verzeichnis nicht gefunden # error/blob.c/OpenBlob/2701.
convert-im6.q16: no images defined `negated/s5_rechts_abgeschnitten.png' # error/convert.c/ConvertImageCommand/3258.
I don't really know what to do, so would be cool if someone got a solution.

jp2:rate gives unexpected output file size

Heyho,
i am using imagemagick 6.8. (2015-03-20) and I tried to convert a .pgm file to a .jp2 file. The output file should be smaller by the factor specified in the jp2:rate=x option, but it does not seem to work.
I am using this command
convert input.pgm -define jp2:rate=20.0 output.jp2
But the resulting file, output.jp2, is bigger than expected (Only compression rate 6 instead of the expected 20)
Could somebody explain this to me please?
The following works for ImageMagick Version 6.7.7-10 2017-07-31 Q16 http://www.imagemagick.org
convert input.pgm -define jp2:rate=0.05 #not 20.0

ImageMagick: how to batch combine multiple TIFF file to a single TIFF file in a directory?

I have 600 TIFF files in a directory, c:\temp.
The file names are like:
001_1.tif,
001_2.tif,
001_3.tif
002_1.tif,
002_2.tif,
002_3.tif
....
....
200_1.tif,
200_2.tif,
200_3.tif
The combined files should be placed in same directory and the files should be named like:
1_merged.tif
2_merged.tif
.....
.....
200_merged.tif
I am looking for any single command-line /batch-file to do so through ImageMagick convert/ mogrify command or any other command/tools.
Please note the overall time taken should not be more than 5 second.
Assuming you want to combine the 600 single-page TIFFs into one single multi-page TIFF (per set of 3), it is as simple as:
convert 001_*.tiff 1_merged.tiff
convert 002_*.tiff 2_merged.tiff
[....]
convert 200_*.tiff 200_merged.tiff
Please note that nobody will be able to guarantee any timing/performance benchmarks... least while we don't even have any idea how exactly your input TIFFs are constituted. (Are they 10000x10000 pixels or are they 20x20 pixels?, Are they color or grayscale?, etc.pp.)
This is different from Mark's answer, because he seems to have assumed you want to combine the input files all into a 1-page image, where the originals are tiled across a larger page...
This should do it - I will leave you to do error checking in case you haven't actually got all the images you suggest!
#ECHO OFF
setlocal EnableDelayedExpansion
FOR /L %%A IN (1,1,200) DO (
set "formattedValue=000000%%A"
set "x=!formattedValue:~-3!"
convert !x!_*.tif +append !x!_merged.tif
echo !x!
)
So, if your images look like this
001_1.tif
001_2.tif
001_3.tif
you will get this in merged_001.tif
If you change +append to -append then merged_001.tif will be like this:
If you remove +append altogether, you will get 200 multi-page TIFs with 3 pages each - same as Kurt's answer.

ImageMagick pdf to black and white pdf

I would like to convert a pdf file to a Black and White PDF file with ImageMagick. But I've got two problems:
I use this command:
convert -colorspace Gray D:\in.pdf D:\out.pdf
But this command convert only the FIRST page... How to convert all pages?
After use this command the resolution is terrible... but if I use -density 300 option the file size has increased more than double. So I would like to use the same DPI setting, but how to use?
Thanks a lot
Assuming you have all the necessary command line tools installed you can do the following:
Split and join PDF using pdfseparate and pdfunite (Poppler tools).
Extract the original density using pdfinfo plus grep/egrep and, for instance, sed. This will not guarantee the same size of the PDF file, just the same DPI.
Putting it all together you can have a series of bash commands as following:
pdfseparate in.pdf temp-%d.pdf; for i in $(seq $(ls -1 temp-*.pdf | wc -l)); do mv temp-$i.pdf temp-$(printf %03d $i).pdf; done
for f in temp-*.pdf; do convert -density $(pdfinfo $f | egrep -o 'Page size:[[:space:]]*[0-9]+(\.[0-9]+)?[[:space:]]*x[[:space:]]*[0-9]+(\.[0-9]+)?' | sed -e 's/^Page size:\s*//'| sed -e 's/\s*x\s*/x/') -colorspace Gray {,bw-}$f; done
pdfunite bw-temp-*.pdf out.pdf
rm {bw-,}temp-*.pdf
Note 1: there as a dirty workaround (for/wc/seq/printf) for a proper ordering of 10-999 pages PDFs (I did not figure out how to put leading zeros in pdfseparate).
Note 2: I guess ImageMagick treats PDFs as just another binary image file so for instance for mainly text files this will result in huge PDFs. Thus, this is a very bad method to convert text-based PDFs to B&W.

On Ghostscript: Fastest way to create a blank .tif document

A legacy backend requires the email body with a .tif document, no tif and it fails. So i need to generate a blank .tif, is there a fast way to do this with ghostscript?
edit: make once in project installation use when i need it.
The following line will produce a 1 pixel Tiff file (340 bytes). That's the smallest Tiff file I could get.
gswin32c.exe -q -dNOPAUSE -sDEVICE=tiffpack -g1x1 -sOutputFile=small.tif -c newpath 0 0 moveto 1 1 lineto closepath stroke showpage quit
Actually, you can even reduce the command to:
gswin32c.exe -q -dNOPAUSE -sDEVICE=tiffpack -g1x1 -sOutputFile=small.tif -c showpage quit
without size gain, alas.
Couldn't you make your blank .tif file once and then attach the same file every time it is needed?
Might be something here: Re: [R] Making TIFF images with rtiff

Resources