I am composing an image from two input images - one with text and one background image.
When using the composite -blur option I get black areas to the right and to the bottom of the overlaying text. Example here:
This is my imagemagick command:
composite -blur 400 -geometry +16+193 example.png background.jpg result.png
I have tried the repage and trim commands to avoid the black areas but that did not work.
Does anyone have a good tip for me?
Related
I have around 2500 images. Some of them contains border while others arent. What I want to accomplish is to add border to the ones that doesn't have any.
Images with border are 64x64 and images without border are 56x56
I prepared a border image file with size of 64x64 in PNG format and I want to merge all files without border within this image to get them borders and output them as PNG format aswell.
I have tried several ways using ImageMagic but no luck so far.
If you make a 64x64 lime-magenta gradient as background.png and a solid blue 56x56 image as foreground.png like this:
magick -size 64x64 gradient:lime-magenta background.png
magick -size 56x56 xc:blue foreground.png
Your command to paste the foreground into the centre of the background is as simple as:
magick -gravity center background.png foreground.png -composite result.png
I figured out it's pretty doable with convert tool from the ImageMagick package.
First I extracted all images with size of 56x56 to different location, then I did the following;
I added 4 pixels on each side since my border is 64x64
for image in ICO_*.png; do
convert -page +0+0 border.png \
-page +4+4 $image \
-background none -layers merge +repage $image-withBorder.png
done
I know it is possible to trim all transparency around image to make image smaller and contain only the image. But is it also possible to somehow know the location of "box", that contains the image?
For example I have 100x100 transparent image, which contains something at 10x10 box having topleft corner at x=15,y=15. Rest is all transparent.
I'd like to end up with 10x10 image, all transparency around trimmed, but also having that 15,15 information. Those are probably 2 separate actions. How do I do this in a script?
Just fyi - I am having bunch of images like this and they are layers, that I need to trim and stack onto eachother to make them clickable.
There are lots and lots of words but no image in your question so I am trying to guess what you want. I made this input image:
magick -size 100x100 xc:black -fill white -draw "rectangle 10,20 50,80" image.png
And I think you want to know the trim box, which is where it would trim to if you ran -trim:
magick image.png -format "%#" info:
41x61+10+20
So that's a 41x61 box with the top-left at (10,20).
Currently, I have thousands of pictures where I want to get rid of white space around the object, but not inside the object. However, the white space is not constant. See pictures below.
Picture 1 :
Picture 2 :
Picture 3 :
Options like this don't work as they delete all white space in the images
convert image.png -fuzz 10% -transparent white output.png
Any suggestions?
What do you mean by getting rid of the white space? If you mean make it transparent, then in ImageMagick 6, you can do a whole folder of images using the mogrify command as follows:
The process involves padding the image with 1 pixel border of white to ensure white is all around. Then doing a fuzzy flood fill. Then remove the extra one pixel all around. I have assumed that the background color is nearly white. Change the fuzz value as desired.
Create a new directory to hold the output (or backup your input directory)
Change directory to the one holding your input images
mogrify -path path_to/outdirectory -format png -bordercolor white -border 1 -fuzz 20% -fill none -draw "matte 0,0 floodfill" -shave 1x1 *.png
Here are the resulting images.
Of course you will have to download them to see that they are transparent.
Note that the images that I downloaded were JPG. So if your images are jpg and not png as in your command, then change *.png to *.jpg. Or just use * to change all formats.
See
https://imagemagick.org/Usage/basics/#mogrify
https://imagemagick.org/Usage/draw/#matte
If using ImageMagick 7, change matte to alpha and change mogrify to magick mogrify.
ImageMagick is premultiplying transparent pixels. This causes a gray outline to appear during subsequent transformations.
For example:
$ convert -size 1085x558 xc:"rgba(0,0,0,0)" PNG32:temp.png
$ composite -gravity center samples/logo_white.png temp.png PNG32:temp.png
Here are the source and resulting images.
Here is a video showing that the temp.png image has had its transparent pixels turned from white to black.
Is there a way to force ImageMagick to leave fully transparent pixels alone rather than changing them to black?
I'm trying to take an image, blur it with a 10px radius (both -blur and -gaussian-blur should work fine), then give it a 50% opacity, and finally overlay the blurred transparent image with the original. Here's what I've got so far:
convert sample.png \( sample.png -gaussian-blur 10 -matte -channel A
-evaluate set 50% \) -composite dreamy.png
Here's the original image:
And here is what it should look like after the effect is applied:
However, what I get with the command above just looks very similar to the original. Anyone have any ideas how to achieve the effect I want? If I do what I originally described in an image manipulation program, I get the desired effect, so something is probably wrong with the command I'm using.
Edit:
-adaptive-blur seems to get me closer to the desired effect, but still I'd like to use -blur.
Edit 2:
convert round-face-winslet.jpg \( +clone -blur 0x10 \) -compose Screen -composite round-face-winslet_soft.jpg
...gets me yet closer to the result, but no matter what kind of -compose method I choose, the result still does not look like the desired image. It's either too light or too dark. What should be a simple 50% opacity blended with the underlying original picture, for some reason doesn't want to work...
I think the effect you are looking for can be found in the ImageMagick compose examples in the "Softened Blurring" section.
convert face.png -morphology Convolve Gaussian:0x3 face_strong_blur.png
convert face.png face_strong_blur.png \
-compose Blend -define compose:args=60,40% -composite \
face_soft_blur.png
Looks like this:
An older tutorial on this technique (here) suggests lightening the blurred layer and blending in Multiply mode. I expect that darkening the blurred layer and blending with Screen would also work. Don't use a standard 50/50 blend - it doesn't have the same glowing appearance.
In your sample, the shadows of the processed image are lighter. Multiplying can only make an image darker, so I'm guessing they took the darken-Screen approach.