On the command line, I can do:
convert sourceimg.jpg | base64
and receive a string of output representing the image.
However, if I add any transformations to the image, nothing is output:
convert sourceimage.jpg -resize 400x400 output.img | base64
Is there a quick way to get the base64 representation of the result of imagemagick commands?
If you want the output image as a PNG, use:
convert input.jpg -resize 400x400 PNG:- | base64
If you want the output image as a JPG, use:
convert input.jpg -resize 400x400 JPG:- | base64
In ImageMagick there is an INLINE: format that will save to base 64. See http://www.imagemagick.org/Usage/files/#inline
So you can also do
variable=$(convert input.jpg -resize 400x400 INLINE:PNG:-)
Related
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
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
I'm trying to convrt RAW image to PNG with Imagemagick.
Imagemagick version I'm using is 6.7.8-9.
The RAW image want to convert is:
https://drive.google.com/file/d/1V1c-ytjkLaCM3KbAc6Yxj2nfWzNkYohc/view?usp=sharing
My client gave me a big RAW image which contains more than 1000 RAW images and it is generated from Dicom. Firstly, I cropped just one image with the command (crop command did not work somehow, so used convert):
convert -size 512x512 -depth 16 UYVY:original.raw result.raw
result.raw appears good on ImageJ.
Now, I have no idea how to get PNG from it.
I tested some commands:
This one generated a very bad quality:
convert -size 512x512 -depth 16 gray:result.raw result.png
This one gets green-ish image:
convert -size 512x512 -depth 16 uyvy:result.raw result.png
If I open result.raw on ImageJ and save as PNG, it works perfectly.
I got an answer from Imagemagick community. Firstly, below code to get the first image from the original raw was wrong.
convert -size 512x512 -depth 16 UYVY:original.raw result.raw
This is the correct way (512*512*2bytes=524228)
head --bytes 524288 original.raw >firstimage.raw
Then convert to PNG:
magick -size 512x512 -depth 16 gray:firstimage.raw -evaluate AddModulus 50% -auto-level x.png
Here is another way in ImageMagick that I think is more intuitive to your signed raw data. I simply specify the data is signed using -define quantum-format=signed. Then stretch the result to full dynamic range using -auto-level.
convert -size 512x512 -depth 16 -define quantum:format=signed gray:original.raw -auto-level result.png
If using ImageMagick 7, then replace convert with magick.
I am trying to convert a list of images (png) to a single PDF using imagemagick.
I've tried using convert *.png -size 375 output.pdf, however the resulting PDF remains much wider than the source images.
How can I get the PDF to match the size of the images - which all have a width of 375px?
Update:
Another way to say this is:
How do I create a PDF with it's page size equal to the height of it's corresponding image?
Update:
To illustrate the problem:
Updated Answer
I created 3 new PNG files with sizes more similar to yours using:
convert -size 375x10000 gradient:red-cyan 1.png
convert -size 375x10000 gradient:blue-magenta 2.png
convert -size 375x10000 gradient:silver-gold 3.png
and put them together in a 3-page PDF like this:
convert [123].png a.pdf
And I get this, which looks correct to me. I can only think you need to update your ImageMagick version, and/or your ghostscript version.
[][]3
Original Answer
Not sure what the problem is, here is what I did and it seems to work fine:
# Synthesise 4 pages, each 375px wide
convert -size 375x800 xc:red 1.png
convert -size 375x800 xc:yellow 2.png
convert -size 375x800 xc:lime 3.png
convert -size 375x800 xc:blue 4.png
# Now assemble into a PDF
convert [1234].png output.pdf
# Check what we produced
identify -verbose output.pdf | more
Image: output.pdf
Format: PDF (Portable Document Format)
Mime type: application/pdf
Class: DirectClass
Geometry: 375x800+0+0
Resolution: 72x72
Print size: 5.20833x11.1111
Units: Undefined
Type: PaletteAlpha
Base type: TrueColorAlpha
...
...
About the ImageMagick command bellow:
imagemagick\convert.exe original.jpg -resize 100x400^ -gravity Center -crop 100x400+0+0 -sharpen 0x0.75 -quality 98% thumbnail.jpg
Some thumbnails generated (in a batch proccess) are not following the original's EXIF data. So they are being generated with the wrong angle. (+|- 90°)
Is there a way to command IM to read the exif data before converting it?
You'll need to add the -auto-orient option.
This operator reads and resets the EXIF image profile setting
'Orientation' and then performs the appropriate 90 degree rotation on
the image to orient the image, for correct viewing.
Example
convert original.jpg -auto-orient -resize 100x400^ \
-gravity Center -crop 100x400+0+0 \
-sharpen 0x0.75 -quality 98% \
thumbnail.jpg