I would like to resize (downscale) some images the way that Facebook does it. ImageMagick, but hey, I'm open for suggestions :)
I believe Facebook is doing this:
Say you have a max width x height of 250x200, Facebook is optimizing the use of this. Tries to use as much of the 250x200 as possible. If for instance you scale down an image and get 220x200, then they cut from the top and the bottom of the image until they use as much as possible of the 250x200 frame. Actually I think they take more from the bottom, than the top (around 1:2.5), which I believe is because most pictures have the head at the top and Facebook realizes this.
Is there any name for this kind of resizing algorithm? And is there any way to have ImageMagick do this?
Thanks in advance!
Edit
It actually appears that Facebook might not be doing this "smart" resizing technique after all. They just resize where they have a minwidth/minheight. Then when they show the image in their album, they cut from the top/bottom or left/right to use as much as possible for the frame (that is how I perceive it at least).
-Tobias
You can use ImageMagick to get the dimensions of an image, scale then crop it. As to whether you are accurately describing the algorithm Facebook uses, I don't know.
I think the following link addresses the problem you're trying to tackle:
http://www.imagemagick.org/Usage/resize/#space_fill
The example they give at the very end is...
convert logo: \
-resize 160x -resize 'x160<' -resize 50% \
-gravity center -crop 80x80+0+0 +repage space_fill_2.jpg
That command resizes an image to be 160 pixels wide, resizes it to be 160 pixels tall, takes the larger of the two resized images and shrinks it by half, and crop it to 80x80.
The following may be of interest to you:
http://www.google.com/search?q=image+entroy+cropping
I've read several documents about using image entropy to choose what part of the image to crop.
Another related link -
Django, sorl-thumbnail crop picture head
edits: added related links, specified an example command for doing a similar task with link to source of example.
Related
I have a series of images. What I wish to do is to literally superimpose these images on top of each other without any other manipulation. The actual example is below
This is the first image
This is the second image
There are five samples like this, each with a tooltip on top of the bar. Essentially, the final image needs have the bars in their full green color with the tool tips showing up on each bar.
The closest I've been able to come up with was using GraphicsMagick which unfortunately does the following with its "average" command.
Any other pointers on how to accomplish this?
Finally: While at this time I just want to get the job done, long term, I will ideally want to use some commandline tool like GraphicsMagick without the need to have a desktop software installed.
You could try using the darken blend mode in ImageMagick:
convert 1.png 2.png 3.png -compose darken -composite result.png
You'd have to tidy up your cropping first though!
I feel silly for having to ask such a simple question, but I have spent the past hour having absolutely no luck whatsoever finding a solution to this. Everyone seems like they need to do the exact opposite of what I need to do.
My question is simply how do I tell mogrify and/or convert to not keep the aspect ratio when resizing an image? I need the image to be an exact power of 2 for both width and height and the images do not come in a 1:1 ratio which means one side has to stretch.
The closest thing I have to an answer is the -extent flag, but that just extends the canvas. I need the original image to fill the entire thing.
After another half hour of searching I have stumbled upon the overly simple answer. The following will resize an image with the exact dimensions given:
mogrify input.png -resize 256x256! output.png
If you want to read more about it, I got the answer from this link:
https://superuser.com/questions/212752/how-to-stretch-an-image-in-one-dimension
use "!" in convert -resize, for ex:
convert "from-img" -resize 800x480! "to-img"
I have a requirement where I need to create a map flag based on a users avatar:
The users avatar can be any size and aspect ratio. The problem I'm having is getting the image to compose correctly, allowing me to get the transparency around the marker in order to support the tick at the bottom.
How can I do this?
It transpires that this is fairly straightforward with the correct approach.
First you need TWO overlay images. One of these is the size of the result image and is transparent everywhere for except where you want the avatar to show. The second is a simple transparent PNG of the surround on the image.
Then, this seems to work:
composite avatar.jpg -thumbnail 61x68^ -gravity center map_marker.png mask.png output.png
I'm trying to make a compilation of 3 thumbs which cover the top of an image. I'm using the following command line command for that:
convert cap/test.jpg -resize 300x -crop 100x135 -strip cap/t.jpg
this resizes the image and cuts it up in 100x135 tiles. But I get more than the top 3 only. I don't need those. I can simply keep the first 3 and delete the rest, but that feels like inefficient programming. Is there a way to limit the number of files written by imageMagick to 3?
eventually I fixed this by making one image with a fixed width and height which I then cut up in 3 separate images. Seems like double work though, since the images are processed twice. Can't be good for the quality either. So here's the workaround:
convert cap/test.jpg resize 300x -gravity north -crop 300x135+0+0 -crop 100x135 -strip cap/t.jpg
but like I said, this processes the image more that absolutely necessary I think. If anybody knows a better solution I'm very interested!
I have about 60 images uploaded to my site. I'd like to resize them all so they fit in a 150px × 100px box. No cropping, just scaling, but it should preserve the original proportions.
I'd prefer a simple solution using, say the ImageMagick convert command. A solution for a single arbitrary image is perfectly fine. (I know how to loop or use find in bash.)
The images are of different types (eps, jpg, ps etc) so a solution that at the same time rasterizes the image would be awesome.
Ok, it seems it was easier than I expected:
convert image.eps -scale "150x100>" file_resized.jpg
did the trick. Reference page.