I am trying to use Rmagick to combine two images.
The image on top can be resized and dragged using Jquery-UI. I get size of the image after r开发者_StackOverflow社区esize using Jquery code such as follows:
ui.size["height"] and ui.size["width"]
I send this data using Ajax to Rails server.
The next step I resize the image using Rmagick resize_to_fit and then use flatten_image to combine the two images as follows:
images=ImageList.new(img1, img2) images[1]=images[1].resize_to_fit!(height, width) images[1].page=Rectangle.new(height, width, x_coord+offset, y_coord-offset1) com_img=images.flatten_images com_img.write(tmpfile.path)
My problem is that the resize image does not seem to work correctly. I am always getting an image smaller than what I want (for different heights and widths tested by resizing image). The image's left top corner is correctly placed (meaning page command is working correctly). I checked my Jquery UI code and ajax and its sending the correct size information. Somehow the information is not being processed correctly by Rmagick resize or flatten_image.
Can someone provide pointers what could be wrong here?
Thanks!
PS: Offsets account for the first image's position with respect to page top-left corner.
I found the solution to the problem Rmagick requires the images when they are resized that they should fit into a square. So the resize_to_fit function works correctly when both dimensions are the same and are the larger one among height or width.
So I changed the code to do the following
if height > width
images[1]=images[1].resize_to_fit!(height, height)
else
images[1]=images[1].resize_to_fit!(width, width)
end
精彩评论