I'm trying to add rounded corners to my images using ImageMagick.
If the input image is a PNG or GIF file my script is working correctly.
But if my input file is a JPEG file, the corners are black. I'd like to use a custom corner color in that case (ex. white) any idea ?
Here's my working bash script :
convert -size "$W"x"$H" xc:none -draw "roundrectangle 0,0,$W,$H,$R,$R" $MASK
convert $SRC -matte $MASK -compose DstIn -composite $DST
Parameters are :
$SRC : the input image
$W : width of input image
$H : height of input image
$MASK : the mask image which contains transparent corners
$DST : the resulting image with rounded corners.
Thanks in advance.
Finally found a solution :
convert -size "$W"x"$H" xc:none -draw "roundrectangle 0,0,$W,$H,$R,$R" $MASK
convert $SRC -matte $MASK -compose DstIn -composite $TMP_PNG
I'm using a "temp" PNG file as destination. If the output format is not GIF or PNG, I use the "flatten" function of ImageMagick with the white color as background.
convert $TMP_PNG -background white -flatten $DST
For PNG output : simply copy $TMP_PNG to $DST
For GIF output : simply convert $TMP_PNG to $DST
Else : flatten the image as said before.
Hope that helps.
Related
I have 3 png image: a red square with a transparent background (1.png), a map (PLAN.png) and a color gradient with a transparent background (LEGEND.png). I want to first put the red square atop the map and then put the color gradient atop of it, while keeping the original filename of the red square for multiple files in multiple folders
Here's what I came up with in the windows cmd:
cd [location of the folder]
magick convert ../PLAN.png 1.png -compose multiply -composite 1.png && magick composite ../LEGEND.png 1.png 1.png
The problem is that for each file, I need to manually change 1.png to for example 1 2 3.png . I had used this command:
magick mogrify -gravity center -draw "image Over 0,0 0,0 '../PLAN2.png'" *.png
While with it I don't have to manually manually change the 1.png, it doesn't work with the map since it put it atop of the red square
In ImageMagick 7, do the following. Note, use magick, not magick convert.
magick PLAN.png 1.png -compose over -composite LEGEND.png -compose over -composite 1.png
or
magick PLAN.png 1.png LEGEND.png -background none -flatten 1.png
Do either of those do what you want?
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.
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
When i want to composite one image with png file i use:
exec("convert 1.png ".$newfile1." -geometry +110+70 -compose DstOver -composite ".$result_image);
And when i want use Perspective i use :
exec('convert '.$newfile1.' -matte -background transparent -virtual-pixel background -distort Perspective "0,0 0,0 393,0 236,65 393,486 393,486 0,486 153,486" '.$newfile1.'');
But with this png file for example :
create Perspective file is very different and hard because i don't know the source image size and how create best perspective..
any help?
(soryy for my bad english)
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