ImageMagick convert from GRAY to TIFF using stdin - image-processing

I have a file I'm saving in raw GRAY format, which then gets converted to tiff. Running the command as follows works:
convert -size 1024X1024 -depth 16 -endian MSB imgTemp.gray /tmp/bla.tiff
but changing to use stdin as the input doesn't:
cat imgTemp.gray | convert -size 1024x1024 -depth 16 -endian MSB -:gray /tmp/bla.tiff
I get the following error:
convert: no decode delegate for this image format gray' # error/constitute.c/ReadImage/532.
convert: missing an image filename/tmp/bla.tiff' # error/convert.c/ConvertImageCommand/3011.
The question is why?

You just have the STDIN and format flipped. "-:gray" should be "gray:-"
cat imageTemp.gray |
convert -size 1024x1024 \
-depth 14 \
-endian MSB gray:- /tmp/bla.tiff
To answer why this is happening. We can run your previous command with a -verbose switch.
cat imgTemp.gray | \
convert -verbose \
-size 1024x1024 \
-depth 16 \
-endian MSB -:gray /tmp/bla.tiff
This will give use an additional line of information that explains what ImageMagick is trying to do
convert: unable to open image `gray':
No such file or directory # error/blob.c/OpenBlob/2638.
convert: no decode delegate for this image format
`gray' # error/constitute.c/ReadImage/550.
convert: no images defined `bla.tiff' # error/convert.c/ConvertImageCommand/3078.
Convert command becomes confused with -:gray and tries to open a blob file entitled "gray", and eventually attempts to open "bla.tiff" as a source image. Both of them non-existing on the filesystem.

Related

Combine multiple command line commands into one single command (pipeline)

How do I combine the following ImageMagick command line commands into a single instruction:
convert -trim "C:\test\test.webp" -quality 95 "C:\test\testMaxNew.webp"
convert "C:\test\testMaxNew.webp" -resize 750x750 "C:\test\testMediumNew.webp"
convert "C:\test\testMediumNew.webp" -thumbnail 100x100^ "C:\test\testSmallNew.webp"
After some trial and error I came up with this:
convert -trim C:\test\test.webp -quality 95 -write mpr:XY +delete \( mpr:XY +write C:\test\testLargeNew.webp +delete \) \( mpr:XY -resize 750x750 +write C:\test\testMediumNew.webp +delete \) \( mpr:XY -resize 100x100^ -gravity center -extent 100x100 +write C:\test\testSmallNew.webp +delete \)
This does the trick but the following errors are reported in the command line prompt:
> convert: unable to open image '\(': No such file or directory #
> error/blob.c/OpenBlob/2695. convert: no decode delegate for this image
> format `' # error/constitute.c/ReadImage/508. convert: unable to open
> image '\)': No such file or directory # error/blob.c/OpenBlob/2695.
> convert: no decode delegate for this image format `' #
> error/constitute.c/ReadImage/508. convert: unable to open image '\(':
> No such file or directory # error/blob.c/OpenBlob/2695. convert: no
> decode delegate for this image format `' #
> error/constitute.c/ReadImage/508. convert: unable to open image '\)':
> No such file or directory # error/blob.c/OpenBlob/2695. convert: no
> decode delegate for this image format `' #
> error/constitute.c/ReadImage/508. convert: unable to open image '\(':
> No such file or directory # error/blob.c/OpenBlob/2695. convert: no
> decode delegate for this image format `' #
> error/constitute.c/ReadImage/508. convert: no images defined `\)' #
> error/convert.c/ConvertImageCommand/3235.
Can someone explain why I am getting these errors and if my code is correct?
The reason I am trying to combine multiple commands is to minimize processing time.
Version: ImageMagick 7.0.2-0 Q16 x64 on Windows 10
These should do what you want.
Best to read the input right after convert.
I am not sure why you need to resize and thumbnail.
So in Imagemagick try one of the following:
convert "C:\test\test.webp" -trim +repage -quality 95 -resize 750x750 -thumbnail 100x100^ "C:\test\testSmallNew.webp"
or just
convert "C:\test\test.webp" -trim +repage -quality 95 -thumbnail 100x100^ "C:\test\testSmallNew.webp"
Just adding an answer to clarify a couple of things that are not a good fit for comments.
You already have some excellent advice from Fred (#fmw42) as regards reading your input image immediately after convert because that way your command will continue to work when you upgrade to ImageMagick v7 which has already been available a couple of years.
You have added a command that works to your question, but that is a bit clumsy inasmuch as it creates an MPR which you don't need and also creates and destroys images unnecessarily - adding to system load which is undesirable if you have many images to process. I think you can see the following is simpler to understand and maintain, makes fewer copies and deletes and demands on memory, and should achieve the same effect as your command:
convert INPUT.webp -trim +repage -gravity center -quality 95 ^
+write LARGE.webp ^
-resize 350x350 +write MEDIUM.webp ^
-resize 100x100^ -extent 100x100 SMALL.webp

Getting Improper image header error in ImageMagick 7.0.7

I am running ImageMagick on Mac OS High Sierra
The following commands work fine with ImageMagick 6.9.0
convert -define stream:buffer-size=0 png:- png:- -alpha off -compose copy-opacity -composite png:-
compare -define stream:buffer-size=0 -fuzz 17% -metric AE png:- png:- png:-
I updated ImageMagick 6.9.0 to ImageMagick 7.0.7-28 then both of these commands started failing with the below error messages
magick -define stream:buffer-size=0 png:- png:- -alpha off -compose copy-opacity -composite png:-
magick: improper image header `/var/folders/tb/11n2czg57ts9dzxypdsmlqk99c46m9/T/magick-26635byT1dtHsAuT3' # error/png.c/ReadPNGImage/4231.
magick compare -define stream:buffer-size=0 -fuzz 17% -metric AE png:- png:- png:-
For input string: "compare: improper image header `/var/folders/tb/11n2czg57ts9dzxypdsmlqk99c46m9/T/magick-26363xwcFdjrv3CT0' # error/png.c/ReadPNGImage/4231."
Can you please guide me what I have to change in those commands?
If I store png files in a temporary folder and run the above commands by replacing png:- with temporary file path then both the commands run fine. But I want the commands to work with InputStream.
Thanks in advance!
I'm not sure you can stream two PNG files concatenated together as PNGs into ImageMagick's input stream. Essentially, you are trying to do this:
{ convert xc:red png:- ; convert xc:blue png:- ; } | convert png:- png:- -append result.png
which doesn't work, because, I think, the final convert will read the entire input stream when it encounters the first png:- and there will be nothing left for the second png:-.
I think the only safe way to send multiple concatenated images through a single channel is by using the MIFF "Magic Image File Format" which does support multiple images:
{ convert xc:red miff:- ; convert xc:blue miff:- ; } | convert miff:- -append result.png

When I try to do a batch magick convert -flatten command on a directory, it fails

I'm, trying to flatten a whole directory of .png images to have a white background.
The following command works on a single file:
magick convert -flatten "c:\Users\LibrarySurface2\OneDrive\Pictures\2016-08-09 archive of coworking space feedback\20151214 115702.png" "c:\Users\LibrarySurface2\OneDrive\Pictures\2016-08-09 archive of coworking space feedback\20151214 115702-white.png"
...however when I try to run it against the whole directory (1300 or so images) using the following command:
magick convert -flatten *.png *-w.png
It fails out with a bunch of these, and then stops running because of "too many exceptions" any thoughts on what could be causing this?
convert: Expected 3949 bytes; found 2684 bytes .\20160426 114948.png' # warning/png.c/MagickPNGWarningHandler/1683.
convert: Read Exception.\20160426 114948.png' # error/png.c/MagickPNGErrorHandler/1650.
convert: corrupt image .\20160426 114948.png' # error/png.c/ReadPNGImage/4029.
convert: Expected 4585 bytes; found 929 bytes.\20160429 145040.png' # warning/png.c/MagickPNGWarningHandler/1683.
convert: Read Exception .\20160429 145040.png' # error/png.c/MagickPNGErrorHandler/1650.
convert: corrupt image.\20160429 145040.png' # error/png.c/ReadPNGImage/4029.
convert: Expected 8192 bytes; found 8037 bytes .\20160504 165938.png' # warning/png.c/MagickPNGWarningHandler/1683.
convert: Read Exception.\20160504 165938.png' # error/png.c/MagickPNGErrorHandler/1650.
convert: corrupt image `.\20160504 165938.png' # error/png.c/ReadPNGImage/4029.
Make a backup first, then use mogrify instead:
mogrify -flatten *.png
Explanation: In general, use the convert command when you want one output file and mogrify when you want multiple output files.

.CDR to .SVG Convert Using ImageMagick

I am on CentOS 6.4 and trying to convert .CDR to .SVG Convert Using ImageMagick using SSH command.
my 1.cdr file is in /var/www/vhosts/website.com/httpdocs/test/1.cdr
once converted to SVG it should be created in the same folder
Tried the following command:
convert /var/www/vhosts/website.com/httpdocs/test/1.cdr image.svg
The Error I am getting is:
sh: mplayer: command not found convert: Delegate failed "mplayer"
"%i" -really-quiet -ao null -vo png:z=3' #
delegate.c/InvokeDelegate/1032. convert: missing an image filename
image.svg' # convert.c/ConvertImageCommand/2800.
Not sure what does that mean ?
In order to convert CDR files you need to install uniconvertor for CDR delegate.
List of all delegates:
convert -list delegate
By default it outputs:
cdr => "uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"
Install uniconvertor. For example, on Ubuntu it’s:
sudo apt-get install python-uniconvertor
Then run:
convert image.cdr -flatten -thumbnail '512x512' image.png
Or, with zoom cropping:
convert image.cdr -flatten -thumbnail '512x512^' -gravity center -crop 512x512+0+0 +repage image.png
And you’re done.
I convert to PNG here but you may use your own output format.
python-uniconvertor is part of inkscape.
It does not exist by itself.
Ubuntu/Mint recently removed all the old Python stuff, for Corel Draw I have to fire up the WinXP VM & Corel and export something Linux understands, usually PNG, a favourite
CDR & WMF files are pretty much dead to Linux, ImageMagick can still handle WMF though.

Cannot create thumbnail in ImageMagick: "convert: no decode delegate for this image format"

I've been at this all day. I'm trying to upload images to a Mediawiki and this is the error I get when ImageMagick tries to create the thumbnail:
Error creating thumbnail: convert: no decode delegate for this image format `/tmp/magick-11924QG1rRXzT948I' # error/constitute.c/ReadImage/552.
convert: no images defined `/tmp/s3thumb-cripEh' # error/convert.c/ConvertImageCommand/3127.
I setup a debug file for mediawiki and this is what I get in the log:
BitmapHandler::doTransform: creating 112x120 thumbnail at /tmp/s3thumb-cripEh using scaler im
BitmapHandler::doTransform: called wfMkdirParents(/tmp)
BitmapHandler::getMagickVersion: Running convert -version
wfShellExec: /bin/bash '/var/www/mediawiki-1.21.2/includes/limit.sh' ''\''/usr/local/bin/convert'\'' -version' 'MW_CPU_LIMIT=180; MW_CGROUP='\'''\''; MW_MEM_LIMIT=202400; MW_FILE_SIZE_LIMIT=102400; MW_WALL_CLOCK_LIMIT=180'
BitmapHandler::transformImageMagick: running ImageMagick: '/usr/local/bin/convert' -quality 80 -background white -define jpeg:size=112x120 '' -thumbnail '112x120!' -depth 8 -sharpen '0x0.4' -rotate -0 '/tmp/s3thumb-cripEh' 2>&1
wfShellExec: /bin/bash '/var/www/mediawiki-1.21.2/includes/limit.sh' 'OMP_NUM_THREADS='\''1'\'' '\''/usr/local/bin/convert'\'' -quality 80 -background white -define jpeg:size=112x120 '\'''\'' -thumbnail '\''112x120!'\'' -depth 8 -sharpen '\''0x0.4'\'' -rotate -0 '\''/tmp/s3thumb-cripEh'\'' 2>&1' 'MW_CPU_LIMIT=180; MW_CGROUP='\'''\''; MW_MEM_LIMIT=202400; MW_FILE_SIZE_LIMIT=102400; MW_WALL_CLOCK_LIMIT=180'
[thumbnail] thumbnail failed on ip-10-168-26-167: error 1 "convert: no decode delegate for this image format `/tmp/magick-11924QG1rRXzT948I' # error/constitute.c/ReadImage/552.
convert: no images defined `/tmp/s3thumb-cripEh' # error/convert.c/ConvertImageCommand/3127." from "'/usr/local/bin/convert' -quality 80 -background white -define jpeg:size=112x120 '' -thumbnail '112x120!' -depth 8 -sharpen '0x0.4' -rotate -0 '/tmp/s3thumb-cripEh' 2>&1"
LocalS3File::transform thumb:
LocalS3File::transform thumbTempPath: /tmp/s3thumb-cripEh, dest: wiki-images/thumb/1/19/5ovrDaU.jpg/112px-5ovrDaU.jpg
info:1
LocalS3File::transform return thumb: MediaTransformError Object
(
[htmlMsg] => Error creating thumbnail: convert: no decode delegate for this image format `/tmp/magick-11924QG1rRXzT948I' # error/constitute.c/ReadImage/552.<br />
convert: no images defined `/tmp/s3thumb-cripEh' # error/convert.c/ConvertImageCommand/3127.<br />
[textMsg] => Error creating thumbnail: convert: no decode delegate for this image format `/tmp/magick-11924QG1rRXzT948I' # error/constitute.c/ReadImage/552.<br />
convert: no images defined `/tmp/s3thumb-cripEh' # error/convert.c/ConvertImageCommand/3127.<br />
[width] => 112
[height] => 120
[url] =>
[path] =>
[file] =>
[page] =>
[responsiveUrls] => Array
(
)
[storagePath:protected] =>
)
Tried from the command line, copy pasted the command from the log (but used a test file):
convert -quality 80 -background white -define jpeg:size=112x120 '' -thumbnail '112x120!' -depth 8 -sharpen '0x0.4' -rotate -0 'logo.jpg'
but the process hangs. If I run:
sudo convert logo.png -quality 80 -background white -define jpeg:size=112x120 -thumbnail '112x120!' -depth 8 -sharpen '0x0.4' -rotate -0 logo.jpg
It works.
If I check DELEGATES, I have:
DELEGATES jng jp2 jpeg png ps tiff xml zlib
I tried increasing the default memory on media wiki to
$wgMaxShellMemory = 202400;
I feel like I've tried anything. Any ideas?
EDIT:
This is what I've discovered so far:
I'm pretty sure the shell wasn't executing the ImageMagick command because of the escaped backslashes in :
wfShellExec: /bin/bash '/var/www/mediawiki-1.21.2/includes/limit.sh' ''\''/usr/local/bin/convert'\'' -version' 'MW_CPU_LIMIT=180; MW_CGROUP='\'''\''; MW_MEM_LIMIT=202400; MW_FILE_SIZE_LIMIT=102400; MW_WALL_CLOCK_LIMIT=180'
Those ''\'' are causing the command to not run, and hence the "no decode" error. It can't decode, because the file is not there. I've traced wfShellEec to GlobalFunctions.php. The wfShellExec function is at around line 2778 on my file.
In the if ( php_uname( 's' ) == 'Linux' ) block there is:
escapeshellarg( $cmd )
I removed the escapeshellarg() function and just left the $cmd on its own.
Tried uploading again, the error is gone, the files are created, but now the thumbnail files are 0 bytes.
Any ideas?
In the following, the empty string parameter '' represents what is supposed to be the input image:
convert -quality 80 -background white -define jpeg:size=112x120 '' -thumbnail '112x120!' -depth 8 -sharpen '0x0.4' -rotate -0 'logo.jpg'
When you ran sudo convert logo.png ... from the command line it worked because you had an input image (logo.png), but inside MW the source image parameter was missing. So the problem here is not with convert, ImageMagick naturally cannot convert an image that doesn't exist. The problem is that MW fails to supply the source image file name.
If your case is like mine, the empty '' image source parameter could trace back to permissions in the images directory. Make sure this directory and all its subdirectories are rwx by the server process. Once I opened up everything in this dir to the server, the errors went away and the images and thumbnails appeared perfectly.

Resources