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
Related
I have a bunch of PNG images (logos) that I want to convert to an all-white color pallet; basically I want to replace all non-transparent pixels with white pixels. Is there an easy way to do this in imagemagick?
You can do that in ImageMagick using -colorize.
convert input.png -fill white -colorize 100 output.png
It will preserve the transparent pixels and make everything else white.
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.
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.
I have to create an image, which is an overlay texture made up of a white image with some transparency to give it the appearance of a rubber stamp.
For reference see the image "stamp_overlay.png" in the video http://railscasts.com/episodes/374-image-manipulation .
This is what i did:
convert -size 70x70 canvas:white stamp_overlay1.png
and then
convert stamp_overlay1.png -transparent white stamp_overlay1.png
But how do I make it like the image?
I am pretty much new to ImageMagick. Any help is highly solicited.
Updated Answer
Ok, I got that wrong! You want to create a stamp overlay, not overlay a stamp overlay. You can do that like this:
# Create white square, draw a black rectangle, then make black pixels transparent
convert -size 300x300 xc:white \
-fill black -draw "rectangle 20,100 200,280" \
-transparent black out.png
Original Answer
I find your question very hard to understand, but I think I know what you want. First, let's create a solid red image
convert -size 70x70 xc:red red.png
then let's composite the stamp_overlay.png image on top
convert red.png stamp_overlay.png -composite out.png
which gives this
but now you want to make the white areas transparent, so you need to do this:
convert red.png stamp_overlay.png -composite -transparent white out.png
and that still looks the same on this white background, but it isn't :-)
I'm after a very specific conversion result from Imagemagick, taking something like this:
And converting it into something like this (1140 pixels wide, 12px border around the top, left, and right of the original):
So far I'm using this code to convert it:
convert nike.jpg -colorspace RGB -density 72 -gravity west -background white -extent 1140x104 nike2.jpg
But I'm getting this very skewed result:
Any advice on how to get closer to my goal here? I guess I'm trying to chain Imagemagick commands here to reduce the size to 78px high, add a 12px border, then extend the background on the right to 1140px wide, and I'm not really sure how to chain commands in Imagemagick via Paperclip.
Solved perfectly:
convert nike.jpg -colorspace RGB -density 72 -resize 78 -gravity west -bordercolor white -border 12x12 -background white -extent 1140x104 nike3.jpg