Rmagick resize and flatten_image error - ruby-on-rails

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 resize 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

Related

Same image slicing displays very different on 8 and 8 PLUS

Here's the Sample Project
Problem
I want to make an image to have a fixed top half part and a stretched bottom half part which to make it properly resized in any height.
And I use image slicing in Assets.xcassets to achieve that. The image can be resized properly, however, it displays slightly different in different sizes.
The Original Image
Image Slicing
Just simply slice the image from the vertical center.
Storyboard
Content Mode is set to Scale to Fill
Height constraint is equal to its width constraint multiplied by 0.8
Result
I think it should display nearly the same images in different devices. Because everything is the same except for the image assets(2x, 3x).
However, the result is not what I expect. The image seems a bit squashed on iPhone 8 PLUS.
At Last
I'm using Mojave with Xcode 10.1 (10B61).
Anyone knows what is the cause. And how to make the image vertically stretched properly?
The reason it looks "squashed" is because the image is being stretched horizontally.
Your slicing allows the top portion to remain a constant height, but not a constant (or proportional) width.
Here, I use your original image without any slicing... each image view is the same height (201-pts), so you know it's not scaling vertically, but different widths so you can see the result of horizontal stretching:
What you may want to try is clipping your original image to only the top portion. Setup the constraints on that image view to stay proportional, and then use a solid color image view (or just a UIView with matching background color), as the lower "vertical stretch" section.

UIImageView - anyway to use 2 content modes at the same time?

So in my scenario, I have a square that is (for understanding's sake) 100x100 and need to display an image that is 300x800 inside of it.
What I want to do is be able to have the image scale just as it would with UIViewContentMode.ScaleAspectFill so that the width scales properly to 100.
However, after that, I would like to then "move" the image up to the top of the image instead of it putting it inside the imageView right in the center, basically what UIViewContentMode.Top does. However that doesn't scale it first.
Is there anyway to do this type of behavior with the built in tools? Anyway to add multiple contentModes?
I already had a helper function that I wrote that scaled an image to a specific size passed in, so I just wrote a function that calculated the scaled image that would fit into the smaller square I had similar to the size AspectFill would do, and then I wrote code that would crop it with the rectangle size I needed at (0,0).

UiPopOver in Iphone

I have an image of the UiPopOver
I want to make it bigger or smaller based on the text that i want to display in this. My plan is that i will adda text view inside the image view and scale it accordingly. I am facing difficulty in scaling the image to bigger or smaller.
For example if i know that the text that will fit in it have size of CGSize(80, 100), the how i can scale this image view to a specified size without pixelation.
Any help will be highly appreciated.
you can make the resizable image with the following insets (their positions marked by the colourful lines below), that will do the job for you:
you can find more information about how you can me a resizable image in the UIImage Class Reference, the related method's name is –resizableImageWithCapInsets:.

How to use a retina image for Trigger.io setTitleImage in native topbar

I am trying to use the setTitleImage feature of trigger.io. I have an image that I saved #2x its original dimensions and am referencing it like so in the my main.js file:
forge.topbar.setTitleImage("img/logo#2x.png");
However, the image does not resize properly and I end up with a huge title image. Please advise on how to set a retina friendly title image in the native topbar.
The image you set will be scaled to the exact height of the topbar if it is larger than it, you probably just need to include some transparent padding at the top and bottom of your image to scale it to the right size.

Resizable Window Resolution

I have an img#myimage whose src is 1000px x 1000px. Then I resize it with .css() to 100 x 100 and apply resizable() to it:
$('#myimage').css('width' : '100px', 'height' : '100px'})
.resizable();
What happens now when I expand it with the resize handles back to 1000 x 1000? Do I still have a million pixels of resolution, or did I lose something when I reduced the width and height with css()?
It seems that I still have the million pixels, but I'd like to get someone else's thoughts on what's really happening here.
jQuery does not actually resize the image, it just scales it. So when you scale it back up to 1000x1000 it will still be the full resolution (because the image hasn't actually changed).
If you wanted to actually resize and save the image you would need server-side code such as php or asp to process the image and send it back to the browser.

Resources