Resize image using ImageMagick and Paperclip based on center point - imagemagick

Let's say I want an image to be resized to 100px x 100px.
I upload Picture A of 200px x 150px. I want it to resize up to ...px x 100px based on the center point. So I don't actually care about the loss sides (the resized 200px).
If I upload Picture B of 150px x 200px, likewise it should be resized to 100px x ...px.
The end result is always 100px x 100px, just that it is positioned in the center.
I have looked through examples in:
http://www.imagemagick.org/script/command-line-processing.php#geometry
http://www.imagemagick.org/Usage/resize/
but can't find out how to do it. Any ideas?

From your description I'm guessing you're talking about
Scaling the image to fully fill 100x100 pixel, even if that means you get 100x123 or 123x100 pixel
cut off any portion of the image that is outside the 100x100 pixel bounds, preferably cut out 50px to each side from the dead center of the image.
What you're talking about is thumbnail cropping. If you're using Imagick, have a look at the handy little method Imagick::cropThumbnailImage().
If you cannot use ImageMagick via the PECL, here's the CLI for cropThumbnail:
convert input.png -resize '100x100^' -gravity center -extent '100x100' output.png

Do this problem in two parts - first of all get ImageMagick to scale the image down to 100px on the longest shortest side. Have a look at man convert for how to do this. Then do the crop on the longer opposite axis, around the centre-point. I should think it would be easier to do it this way than to do it in one go, but the latter is possible with IM.
(Corrected from the version in the comments)

Related

vipthumbnail resizing image without aspect ratio

i want to resize my 800x800px image into 500x1000px using libvips vipthumbnails.
we know that we can force vipthumbnail to ignore aspect ratio and do whatever dimension we want but it will simply distort the image.
resizing 800x800px image to 500x1000px will simply distort the image if we force to follow the given dimension
we simply wants to resize first to 500x500px and then on longer side add the white space in both direction equally distributed. in this case given width is 1000px so both side we will add 250px white space and align the 500x500px part in centre.
so the final image will be 500x1000px and 500x500px image with proper aspect ratio in that frame
vipsthumbnail "/path/original.jpg" --size 500x -o "/path/resize.jpg"[Q=90]
any help will be great. i dont want to use imagemagick as it consumes more memory

Final Cut pro X cropped output media

I've created simple 7 seconds clop which uses standard plugin for FCPX: "Bold Fin" title.
While i am editing this clip - everything fits to the screen:
also everything is ok when i am starts to export this clip to the master file:
but when actual file is ready - it seems like it is cropped:
Could somebody please help to find a reason why my output actually cropped? And how fix this issue?
Judging by the image you provided, you have non-square pixels in your footage or in projects settings (or footage's aspect ratio isn't 16:9). I print-screened the image inside FCP's canvas and found that you have rectangular pixels stretched along X axis, instead of square ones.
Seemingly, FCPX trying to compensate pixel aspect ratio for FullHD export (par = 1.0, ar = 16:9), stretched pixels along Y axis, which led to cropping.

How to batch convert images to a specific megapixel with Imagemagick?

I'm sorting my photos and want to resize them to something reasonable. Now the input files are a wild mix of small and big images, some landscape, some tower.
I want to resize them all (above a threshold) to a specific megapixel size, but all descriptions I found so far only resize to either a fixed size / aspect ratio (e.g. 1024x786) or a fixed percentage (e.g. 50%). None of these seem to apply with a folder that has some small images (e.g. 300x400) and images mixed in the range of 3-12 megapixel.
I'm looking for an aspect ratio independent option that puts them all in the same megapixel ballpark. Any suggestions?
Add \> at the end of your resize to only down-res larger images and not affect smaller ones and maintain aspect ratio too.
convert -resize 1200X800\> image.jpg
Or if you want a specific number of pixels, regardless of whether landscape or portrait, you can do
convert -resize 1000000#\> image.jpg
so you get a million pixels max, which may be 400x2,500 or 2,500x400 for example.
EDITED
I should maybe point out that the backslash in front of the greater than symbol is a shell escape to stop the shell deciding to redirect output like it normally does when it sees a greater than symbol. You could equally enclose the resize specification in single quotes to prevent the shell seeing it. If that doesn't make sense, then the following two commands are identical:
convert -resize 1000000#\> image.jpg
convert -resize '1000000#>' image.jpg

Resize image with mogrify without keeping aspect ratio

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"

Facebook-like resizing of images using ImageMagick

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.

Resources