I want to blur an image with transparent background using ImageMagick. I've trimmed this image to its content, so it doesn't have any surrounding whitespace/transparency.
The above part works fine, but:
When I blur the trimmed image, it will (obviously) overflow the boundaries. So the question is: How can I blur a trimmed image, while extending its boundaries to the right size before?
Extend the background with transparent pixels, blur and then re-trim:
convert original.png -background none -gravity center -extent 200x200% -blur ... -trim result.png
Related
I have an image that all four margins are transparent alpha channels and I want to crop all margins and only keep the non-alpha channel parts. Is there any way to do it with ImageMagick? Take this image as an example but consider its transparent margins!
You can do that in Imagemagick using -trim to automatically remove the constant transparent regions.
convert img.png -trim +repage result.png
I have an image of 4500x5400, I want to resize it for the height 4200 keeping the width ratio, however the width of the image needs to be 4050, leaving the sides transparent.
I have this ImageMagick command:
convert file.png -resize 4500x5400 -gravity center -background transparent -extent 4050x4200 out.png
However it's cutting the top and the bottom, while it needs to appear.
Do you guys have any idea of how I can make it work?
Appreciate your time!
Try this...
convert input.png -resize 4050x4200 -background none -gravity center -extent 4050x4200 output.png
The "-resize" fits your input image within a container of that size. The "-extent" makes sure the total canvas is that size. The "-background" and "-gravity" make sure extra space is filled with transparent and that the input image is located in the center of the output canvas.
So here is my original image (note the transparent border) src.png:
Here's the mask I want to use to crop. White means keep, black means crop mask.png: (Note that it isn't necessarily going to be a square. It could be a heart or a star or anything)
I also have transparent.png, which is a fully transparent image. All three images have the same dimensions.
So, running this command generates the following image:
convert transparent.png src.png mask.png -composite out.png
Which is masking perfectly, but now I want it cropped to the size of the white mask area. Using -trim is sort of close, but it gets rid of the transparent areas that are inside the mask.
How can I resize the masked image to the size of the white area in the mask?
I am not sure I understand what you want for the result. Why do you need the fully transparent image? Do either of these do what you want?
Full sized transparent image with masked area showing:
convert src.png mask.png -alpha off -compose copy_opacity -composite result1.png
Trimmed to just the part you want:
convert src.png mask.png -alpha off -compose copy_opacity -composite -trim +repage result2.png
Not sure I understand what you are trying to do, not least why you need a full size transparent canvas. Your command does not give the same results on my ImageMagick version 7.
This command may be what you are looking for:
convert src.png mask.png -compose darken -composite -trim out.png
It gives this - I have artificially added a red border so you can see the full extent on StackOverflow's white background:
Or maybe you want the trim box from your mask and to use that to crop your source:
convert mask.png -format %# info:
113x113+570+33
convert src.png -crop 113x113+570+33 result.png
If you want to crop a square from picture, you no needs using mask, just crop it:
magick Uq328.png -crop -crop 111x111+570+331 +repage cropped.png
according to https://legacy.imagemagick.org/Usage/crop/
I want to add a tiled background to a transparent image.
According to the docs this should do it:
convert test.png -texture paper.png result.png
I also tried other variations (with -composite, -flatten, -tile, etc.) but result.png is either still transparent or just gets a white background.
ImageMagick-6.8.7-5 on Windows.
I got it to work with
convert -size 4096x4096 tile:paper.png test.png -flatten result.png
Getting started with ImageMagic and trying to find a way to do this... If an image is less than 50 pixels tall or 50 pixels wide, I'd like to place it (un-scaled) in the horizontal/vertical center of a new 50x50 pixel canvas on top of a white background - and save that as the new image. Anyone know if this is possible with ImageMagick? Thanks!
I used -extent to do this:
convert input.jpg -gravity center -background white -extent 50x50 output.jpg
I wanted to do the same, except shrink the image to 70% inside. I used this:
convert input.png -resize 70%x70% -gravity center -background transparent -extent 72x72 output.png
Not exactly what was requested but hopefully it will help someone ;).
I have once used this code to place an image in the center of a new canvas with white background. hope this will help you
convert -background white -gravity center your_image.jpg -extent 50x50 new_image.jpg
See cutting and bordering for a huge number of examples. Here's one simple way you might do it:
convert input.png -bordercolor Black -border 5x5 output.png
Of course, you'll need to calculate the size of the border to add (if any) based on the dimensions of the input image. Are you using an ImageMagick API, or just the command line tools?
I tried this:
convert test.jpg -resize 100x100 -background black -gravity center -extent 100x100 output.png
You can use single composition to do this. So it would look something like this:
convert -size 50x50 xc:white null: ( my_image.png -coalesce ) -gravity Center -layers Composite -layers Optimize output.png
To modify the source image you need to use mogrify:
mogrify -gravity center -background white -extent 50x50 source.jpg
If an image is less than 50 pixels tall or 50 pixels wide
In my case, the images were much larger than the destination canvas, and weren't square. So I resize them proportionally to fit inside. Example:
convert in.png -resize 46x46 -background none -gravity center -extent 50x50 out.png
The 46x46 limit ensures a 2 pixel margin minimum. Note that the above does not distort the image, e.g. a rectangle does not become a square.
I used background none for a transparent background, but you can choose a solid color instead.