Create blank image in Imagemagick - imagemagick

How to create a blank new image in Imagemagick via command line?
Using -background doesn't work:
$ convert -size 800x800 -background white x.png
convert: no images defined `x.png' # error/convert.c/ConvertImageCommand/3257.

White background
convert -size 800x800 xc:white white.png
xc: used to mean "X Constant Image" but now is just a shorthand for canvas:. This means you can also use:
convert -size 800x800 canvas:white white.png
and because "white" is the default value if no color is provided, you can also use:
convert -size 800x800 xc: white.png
convert -size 800x800 canvas: white.png
Transparent background
If by "blank" you mean "transparent", just use that word as the color:
convert -size 800x800 xc:transparent transparent.png
Answer made possible by ImageMagick v6 Examples and How to create a new image?

You need to supply PNG24, PNG8 or PNG32 prefix if planning to use this canvas to layer colour images over. Without it, it creates a Grey colour space. I used 32, as I need "varying degrees of transparency for each pixel" (pixel art)
convert -size 800x800 canvas:transparent PNG32:canvas.png
For more about PNG types see this link.

Related

Magick++ -label equivalent

Trying to convert the Image Magick convert command:
convert -size 50x50 -background white -fill black -gravity center label:Ryan test.gif
to magick++/PythonMagick. Cannot use annotate since I need to have the text auto-sized, which 'label' does. I can do
img = PythonMagick.Image('50x50', 'none')
img.backgroundColor('white')
img.fillColor('black')
img.read('label:Ryan')
img.write('test.gif')
but img.read does not allow me to specify gravity. Is there a way to do this without using subprocess or os?

Set image inside png transparency

As the title suggests I have a PNG image that has some transparency. I'd like to fill that transparency with a second image (which is currently a JPEG, but it's not a problem to convert it to a PNG).
Every post I have found searching on the Internet was about the "inverse" problem (from an image with a background to an image with transparency), so obviously it did not work out for my situation; for example, I tried
convert -flatten myimg.png myimg.png
(taken from here) and
convert myimg1.png -transparent white myimg.png
(taken from here).
In ImageMagick 6, if the two images are the same size, then you can just flatten the transparent image over the background image.
Background (lena.jpg):
Transparent (logo_crop_trans.png):
convert lena.jpg logo_crop_trans.png -flatten lena_logo.jpg
If using ImageMagick 7, then change convert to magick.
If you want to anti-alias the transparent image so that it is not so jagged, then use some blur to smooth the outline (Unix syntax):
convert lena.jpg \( logo_crop_trans.png -channel a -blur 0x1 -level 50x100% +channel \) -compose over -composite lena_logo2.jpg
If on Windows remove the \ before the parentheses.

ImageMagick script takes JPG and places on canvas but changes colour of JPG

I would like to take this logo and place it on a black background.
I am using the below script
convert -size 4000x4000 canvas:#000000 -background \#000000 background.jpg
composite rev.jpg -gravity center background.jpg output.jpg
open output.jpg
Which generates. As you can see the colours have changed and I cannot work out why?
Just set the colorspace.
composite 03wp2.jpg -colorspace srgb -gravity center background.jpg output.jpg
Possibly a colour profile or are you using CMYK for the rev.jpg?
Try this which will shorten your code:
convert rev.jpg -background black -gravity center -extent 4000x4000 output.jpg

How to convert gray scale png image to RGB from comand line using image magick

I am trying to convert an png Gray scale image to RGB png image using the following command.
convert HopeLoveJoy.png -size 1x1 -fill "rgba(0%,1%,2%,0)" -draw "color 511,511 point" out_test.png
By using the above the above command I am able to convert but the color of the image is getting changed.
Is any thing wrong in the command??
Any help is appreciated.
Thanks in advance.
If, as your question title implies, you really just want to go from greyscale to sRGB colorspace, use this:
convert image.png -define png:color-type=2 result.png
I check it like this:
convert image.png -define png:color-type=2 result.png && identify -format "%[colorspace]" result.png
sRGB

imagemagick: create a .png file which is just a solid rectangle

I want to create a .png file which is just a solid color.
This must be easy to do using ImageMagick but I can't figure out the problem:
C:\tmp>convert -size 8x16 -stroke black -fill black -draw "rectangle 0,0,8,16" black.png
Magick: missing an image filename `black.png' # error/convert.c/ConvertImageComm
and/3016.
Obviously there can be more options, like borders and etc, but if you just want an image of width x height of a given hex color, it's pretty straight forward.
Here's all it takes to make an 100x100 image of a solid dark red:
convert -size 100x100 xc:#990000 whatever.png
Note that for rgb and rgba values, you need to escape the parentheses. Building on #Mike Flynn and #luk3thomas (who correctly escapes the color code):
convert -size 100x100 xc:rgb\(0,255,0\) whatever.png
convert -size 100x100 xc:rgba\(0,255,0, 0.4\) whatever.png
In Mac
convert -size 100x100 xc:"#8a2be2" blue#2x.png

Resources