This is the original image of 200x200
On downscaling the image to 100x100. There is a semi transparent shadow near the lines and some pixels are not completely opaque.
The command used for scaling:
ffmpeg -i test.png -vf scale=100x100 out.png
I have also tried scaling with this command:
ffmpeg -i test.png -vf scale=100x100 -sws_flags neighbor out.png
The shadows are gone but the top line has also vanished.
How do I fix this ?
Related
I've a folder with several images with different size (i.e. 1284x456, 1290x445 and so on...).
I need to convert each image to 1920x1080px:
enlarging the sizes proportionally so that I have them 1920px large (i.e. 1920x681, 1920x662 and so on...);
and then adding a white background so that the final height of the output image becomes exactly 1080px (with the old image vertically centered).
Is it possible with a single command?
thanks
I think that I found the trick:
for i in *.jpg; do convert -resize 1920x1080 -gravity center -background white -extent 1920x1080 $i `basename $i `.JPG; done
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 would like to blur only a part of an image. The part to blur is always rectangular, so that I can easily use the following command:
magick source.jpg -region 1000x1000+0+500 -blur 0x20 result.jpg
This works, but is pretty slow for large images. Since I have to process thousands of files again and again, this will simply take too long.
Therefore, I decided to do the blurring by downscaling and upscaling the image back to the original size. However, since this will blur the full image, I have tried to accomplish the task using the following steps:
take the original image as background
create a copy of the original image
blur the copy using down-/upscaling
crop the desired region from the blurred copy
compose the original and the blurred&cropped copy
I am already pretty close (I hope), but when composing the two images, the cropped image will always be positioned in the top-left corner of the original image - instead of the original position from the source image. This is my current command:
magick source.jpg ( -clone 0 -resize 5% -resize 2000% -crop 1000x1000+0+1000 ) -composite result.jpg
I have read in the documentation that the original canvas size will be retained when using the -crop operation, and that this size and position will be used when using -composite. However, this doesn't seem to work in my case. Does anyone have an idea why?
I have tried to use -repage, -extent and other options to define the size and position of the cropped image, but to no avail so far.
I would try -flatten in your command as that is used for layers.
You can do it with a mask image (of any shape) in ImageMagick. Though I am not sure if that will be faster than your scaling method.
Input:
Mask:
(note: blurring occurs where mask is black)
magick lena.jpg -write-mask mask.png -blur 0x3 +write-mask lena_blurred.png
Result:
I am using Mogrify in Ubuntu to scale my images to lower size that is working fine for most of the images.
Problem is my all PNG images are above 30MBs and if I try to scale them to 300kB it starts to disturbs the background colors and fade them off.
What I do is:
Convert png image to jpg using below command.
find . -iname '*.png' -exec mogrify -format jpg "*.png" {} +
At that point everything stay same and fine but size is still 30MBs
Then I do below command to give it low size but it disturbs colors of entire image.
find . -iname '*.png' -exec mogrify -define jpeg:extent=300kb -strip -quality 90 -scale 90% *.jpg {} +
How I can easily convert my images sizes to 30kBs or even 40kBs without disturbing the image colors.
My main goal is to preserve original colors. It does work but now its not!
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?