I want to convert image in less pixelate with ImageMagic and I give a try with
convert -resize 20x20 -flop -gaussian-blur 1x5 -scale 100% -scale 500% -colorspace gray -quantize sRGB +dither /png.png /sam_pic.png
And its looking like the following image:
But I want to Increase pixel size that is Image with less pixel
Please suggest me how to do it and modify command.
I got the solution.
Only change the size and increase the scale
convert -resize 18x18 -flop -gaussian-blur 1x5 -scale 110% -scale 500% -colorspace gray /png.png /sam_pic.png
Related
I'm using ImageMagick to trim some PDFs of text that I've converted to jpg for a project. In most cases it works well but when the page has just a small amount of text, say half a sentence, trim works too well so the image is just that, half a sentence.
It's a problem as it causes some display issues where I'm presenting it so it'd be helpful if there was a minimum image size. Is there a way of doing that in ImageMagick? Or adding padding to an image if it is converted below a certain size?
This is the command I'm using:
convert '*.jpeg' -fuzz 1% -trim +repage -set filename:base "%[basename]" "%[filename:base].jpg"
I'm using ImageMagick 7.1.0-19 Q16-HDRI arm 2021-12-22
Currently there is no way that I can think that would limit the trim in that way in Imagemagick. But you can automatically pad the image with some color such as white to some minimum size.
However, you will need to use "magick" in place of "convert" for Imagemagick 7 to make it work properly.
Input (256x256):
Lets pad it with white to 100x100 (minimum)
magick image.png -fuzz 1% -trim +repage -gravity center -bordercolor white -border "%[fx:w<100?round(0.5*(100-w)):0]x%[fx:h<100?round(0.5*(100-h)):0]" result.png
or better
magick input.png -fuzz 1% -trim +repage -gravity center -background white -extent "%[fx:w<100?100:w]x%[fx:h<100?100:h]" result.png
I had the exact same question recently, and the answer was to combine -trim and -extent.
convert -trim -background none -gravity center -extent 1024x1024 input.png output.webp
The image will first be trimmed, then extended to a given size.
You might want to change -gravity and -background depending on your use case.
I'm trying to crop an animated gif usind convert -crop. In some cases it's necessary to add more background to the image to fit. With other image formats it's done with
convert original.gif -rotate 0 -crop 1519x759-237-61\! -background white -flatten edited.gif
For gifs I tried
convert original.gif -coalesce -rotate 0 -crop 1519x759-237-61\! +repage edited.gif
convert is clipping/trimming the background and just the "subject" of the image is shown.
Example is here: https://imgur.com/ls1ED0Z
Result is here: https://imgur.com/59678cD
Expected Result is https://imgur.com/vZGaD7r
I added the red border to show how big the image is. Someone with a great solution? :)
Jan
To do what you want in Imagemagick, you should be using -extent rather than -crop in order to extend the size of the output.
Try this. Adjust the size and offset and background color as desired.
convert original.gif -coalesce -rotate 0 +repage -background white -extent 1519x759-237-61! -bordercolor red -border 3 result.gif
I have added a red border around the image.
With IM you can choose to "-crop", which is most often used to reduce the viewport dimensions, or "-extent", which can also be used to enlarge the viewport. It looks like there are a couple other issues with achieving the result in your sample image, but for starters, try simply substituting your "-crop" with "-extent" like this...
convert original.gif -coalesce -rotate 0 -extent 1519x759-237-61 +repage edited.gif
That will put your input image in a viewport of 1519x759, and place its upper left corner at 237 pixels from the left and 61 pixels from the top. You shouldn't need the exclamation point "!" in any case.
I would like to zoom into an image test.png. That is, as a silly example, I would like to go from this
to this
The only way I was able to do it was with
convert -resize 110% test.png -gravity Center \
-crop 800x600+0+0 +repage 1.png
This is re-scaling the picture and then cropping it to its original size. The problem is that this only works because I already know that the original size of the image is 800x600.
How can I make this work without knowing the size of the image beforehand?
The way to do this, apparently, is with the -distort option:
convert -distort SRT '1.1 0' +repage test.png 2.png
where 1.1 is a 110% zoom and the 0 is a rotation angle.
I need a truly random BMP in order to test various lossy image compression algorithms. Ideally, this would not rely on any library and run in a Linux CLI.
It should generate a random BMP given a certain width and height.
Updated Answer - April 2021
Here are some more ideas for random images:
Random coloured squares
magick -size 8x8 xc: +noise Random -scale 100x100 RandomColouredSquares.png
Random black and white crosswords
magick -size 8x8 xc:gray +noise Random -threshold 50% -scale 100x100 RandomCrosswords.png
Random grey blur
magick -size 8x8 xc:gray +noise Random -resize 100x100 RandomGreyBlur.png
Random coloured blur
magick -size 5x5 xc: +noise Random -auto-level -resize 100x100 RandomColouredBlur.png
Random salt and pepper
magick -size 100x100 xc:gray +noise Random -threshold 1% -negate RandomSaltAndPepper.png
Repeated coloured pattern
magick -size 50x50 xc: +noise random -virtual-pixel tile -blur 0x6 -auto-level -write MPR:tile +delete -size 250x250 tile:MPR:tile RandomRepeatedPattern.png
Updated Answer - March 2021
If you want random-noise type of images, see original answer below, noting that you should replace convert with magick in those examples if working with ImageMagick v7 onwards.
If you want images of a solid random colour, you could do something like this:
magick -size 400x200 xc:"rgb($((RANDOM%255)),$((RANDOM%255)),$((RANDOM%255)))" image.png
Sample Outputs
If you want images of a random size and a random solid colour, you could use this for images between 200..264 pixels wide by 100..132 pixels tall:
magick -size "$(((RANDOM%64)+200))x$(((RANDOM%32)+100))" xc:"rgb($((RANDOM%255)),$((RANDOM%255)),$((RANDOM%255)))"random.png
Sample Outputs
Original Answer
You can use ImageMagick (which is installed on most Linux distros by default) to generate an image of random noise like this:
convert -size 300x200 xc:gray +noise random out.bmp
where 300 is the width and 200 is the height (just examples).
Other types of noise are available, just run
convert -list noise
Output
Gaussian
Impulse
Laplacian
Multiplicative
Poisson
Random
Uniform
If the noise is too noisy ;-) for you, you can attenuate it with
convert -size 300x200 xc:gray -attenuate 0.5 +noise random out.bmp
for a 50% attenuation
Here are some examples of the different types:
Here are the corresponding distribution histograms:
Just for completeness, note that this answer features in Daniel Barrett's book "Efficient Linux at the Command Line".
I'm using graphicsmagick to resize an image to a thumbnail, but it's adding a white surrounding border padding.
The command I'm using is:
gm convert matrix.jpg -resize "80x80>" -gravity center -extent 80x80 thumbnail.jpeg
As you can see, there is some white padding around the image, but I don't want this. Ideally I'd like (the entire image not just a crop of it) to fill the desired 80x80 output size.
How can this be achieved in either imagemagick or graphicsmagick?
I used ImageMagick with this image. This solution requires to know the size of the input image.
Input
The image has 145 pixels horizontally and 200 pixels vertically.
Crop
Crop from the top of the image:
convert -crop 145x145+0+0 -resize 80x80 matrix.jpg thumbnail.jpeg
I used 145x145 in order to extract a square from the original image. +0+0 is the offset of the extracted square, hereby the top left.
Crop with the center of the image:
convert -crop 145x145+0+27 -resize 80x80 matrix.jpg thumbnail.jpeg
The vertical offset is set to 27 because we have to remove 55 (200 - 145) pixels on top or bottom, so we need to remove 27 (55 รท 2) pixels on the top and 28 pixels on the bottom.
Crop with the bottom of the image:
convert -crop 145x145+0+55 -resize 80x80 matrix.jpg thumbnail.jpeg
Resizing without crop
convert -resize 80x80\! matrix.jpg thumbnail.jpeg
The ! flag (escaped with \! as suggested in the documentation) after the resize parameters forces ImageMagick to ignore the aspect ratio.
If you want to keep the original aspect ratio, without image distortion, you can use the ImageMagick -trim option to get rid of the white padding:
convert "matrix.jpg" -resize "80x80" -gravity center -extent 80x80
-trim "thumbnail.jpg"
This will produce a 58x80 uncropped image with the same aspect ratio as the original. It is 58x80 because ImageMagick uses the larger dimension of the original to compute the scale factor (in this case 80/200) and scales the smaller dimension by that same factor to preserve aspect ratio.
If you want an uncropped image of exactly 80x80 pixels, this is a different aspect ratio than the original. The output image will have distortion, and #AL's resizing without crop option will work.
convert "matrix.jpg" -resize "80x80!" -gravity center -extent 80x80
"thumbnail.jpg"
Tested in Windows 7 with ImageMagick 6.8.9. #AL syntax is probably Linux.