I am using a jQuery plugin that allows basic image manipulation: cropping, rotating, zooming, etc.
I am able to rotate the image:
image = photo.image.rotate(wrapper.rotate)
I am able to crop the image
image.thumb("#{wrapper.width}x#{wrapper.height}+#{wrapper.x}+#{wrapper.y}")
However, I can't figure out a way to resize the image after cropping it. Basically, I want to run:
image.thumb("300x200!")
once more.
I understand that image.thumb() returns a Dragonfly job, is it possible to preform another process after cropping it?
Some context on why I want to do this: The user can pan over a specific area of the image which will than be visible in a 300x200px container. Most of the time, the image is way larger than 300x200px, so I want to re-size it after cropping it to reduce the filesize.
instead of trying to do it with the given methods, just use .convert and pass the normal image magic arguments as one lone string e.g
image.convert("-gravity center -crop '#{wrapper.width}x#{wrapper.height}+#{wrapper.x}+#{wrapper.y}' -resize '300x200!'")
Related
I have a RubyOnRails application.
I use carrierwave for images uploading and jcrop for cropping.
I have two images: original and cropped image.
But I have no saved coordinates of this cropping (crop_z, crop_y, crop_w and crop_h)
Is there any way to get cropping coordinates via Rmagick or something another solution?
Thanks
In general I don't think the crop coordinates are recorded in the image metadata. (They're saved in the metadata in the Magick format but very few people save their images in that format.) However, you may have some luck detecting the position of the cropped image in the original using the find_similar_region method. Pass the cropped image as the target argument. If this method finds a region in the original that matches the target it returns the x- and y-offset of the region. The width and height of the region, of course, are the width and height of the cropped image.
I'm building a Rails application where a user can upload an image which is automatically cropped to a certain size, then they can choose an overlay which is exactly the same size as the cropped image.
What I want to do is composite or flatten the two images and save it as a single image - I've looked at the Image Magick documentation, but I can't see how to apply the example they give:
composite -gravity center smile.gif rose: rose-over.png
to work with Paperclip.
Also, the example references two specific images, but I'm wondering how I can pass in a variable (the user uploaded image) instead?
I believe you want to use a paperclip processor.
Here is the high level description:
https://github.com/thoughtbot/paperclip#custom-attachment-processors
Here is a gist example of using composite (recommended here https://github.com/thoughtbot/paperclip/issues/978):
https://gist.github.com/708077
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 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.
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.