Convert image from one format to another sent to STDOUT - imagemagick

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

Related

imagemagick convert -crop with pipe before it

I want to use imagemagick to crop an image.
However, imagemagick will be receiving the image data to crop through a pipe before it:
exiftool -b -RawThermalImage image1.jpg | convert .....-crop.....
I am not sure what to put in the ".....-crop.....", to crop the image data received to a specific area. Please guide.
Usually, after convert, an image is specified for cropping like:
convert rose: -crop 1x1+3+3 cropped.gif
But, in this case, I am confused as to how to complete this command given that the image is coming in from the pipe.
ImageLink:
https://drive.google.com/file/d/14h3z0yFK_9_f2puzbhLUm3D50MDMMnu2/view?usp=sharing
Updated Answer
It transpires that the problem was caused by inadvertently using GraphicsMagick rather than ImageMagick.
Original Answer
You should be able to use a dash - to refer to the stdin if that stream has a well-known magic number (signature) at the start:
exiftool -b -RawThermalImage image1.jpg | convert - -crop ... result.jpg
If the stream is raw, or doesn't have a known magic number/signature, you will need to give ImageMagick a hint, so if it is raw greyscale 8-bit data with shape 640x480, use:
exiftool -b -RawThermalImage image1.jpg | convert -size 640x480 -depth 8 GRAY:- -crop ... result.jpg
If it's RGB888 data with size 80x80, use:
exiftool -b -RawThermalImage image1.jpg | convert -depth 8 -size 80x80 RGB:- -crop ... result.jpg

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.

How do I convert EXR to PNG and adjust brightness at the same time

I was able to convert my EXR image to a PNG using the techniques outlined in Image conversion from IFF and EXR formats to JPEG format .
convert 0007.exr /tmp/0007.png
Unfortunately the PNG looks quite dim.
What should I add to the imagemagick convert command line to increase the brightness?
Starting with this:
You could try -auto-gamma:
convert start.jpg -auto-gamma result.jpg
If the -auto-gamma overcooks the image for your liking, you could apply a percentage of it. So, here I clone the original image and apply auto-gamma to the clone but then only blend 80% back into the original because I feel auto-gamma overdoes it:
convert start.jpg \( +clone -auto-gamma \) \
-define compose:args=80 -compose blend -composite result.jpg
Or, another option, you could experiment with your particular images and maybe try using -modulate for the brightness, where 100% means "do nothing", so numbers over 100 increase the brightness:
convert start.jpg -define modulate:colorspace=LCHuv -modulate 160 result.jpg
You can try -auto-level, which will take the minimal value and the maximal value of your picture and then stretches the values to the full range of values:
convert input.exr -auto-level output.jpg
Note that if you picture was too bright and this does not help, then it might be that your image is stored with 32 Bit, while ImageMagick is working with 16 Bit and no HDRI support. 32 Bit input is supported if convert --version
either show Q32 as part of the version string or lists HDRI under features.
Depending on your operating system you might be able to install another variant of ImageMagick. For example, for Debian Buster we can use sudo apt list imagemagick* to see that the package imagemagick-6.q16hdri is available. Installing this package provides convert-im6.q16hdri, which allows reading 32 Bit EXR images.
EXR is in linear RGB colorspace. You want to convert it to non-linear sRGB colorspace in Imagemagick as:
Input:
convert image.exr -set colorspace RGB -colorspace sRGB output.png

How to convert a jpg into a 24-bit uncompressed BMP 4.0?

I've tried using image magic but it converts the image into a compressed format and most of the online conversion tools are also doing the same thing.
Is there some way i could achieve this in image magic or anywhere else?
Use the ImageMagick "-compress none" option to prevent compression, and use "-define bmp:format=bmp4" to force BMP4.0:
convert in.jpg -define bmp:format=bmp4 -compress none out.bmp
You can omit defining the bmp4 format because that's the currently the default BMP output format for ImageMagick anyhow.
Add "-alpha on" if you need RGBA instead of RGB pixels.
See the ImageMagick documentation for the -compress and -define options.

create GIF image with fixed colormap using Image Magick

I want to save .gif conversions of other images with a specified colormap. The "-remap cmap.gif" option in Image Magick
example: convert -remap cmap.gif input.png output.gif
DOES process input.png using the specified colors from cmap.gif, but it changes the order in the output colormap. Is there a way to force Image Magick to used EXACTLY the same colormap?
I am attempting to add new images to an ancient display program that accepts .gif file input but uses a fixed colormap with no ability to alter the colormap for individual images.
Does it help to add the +dither parameter?
convert input.png -remap cmap.gif +dither output.gif

Resources