Shrinking a border image to fit inner image
Posted: 2008-12-08T01:11:47-07:00
I was hoping someone might be able to give me some help with the following problem.
I have a few border images, such as the following:
and a large number of images that I need to place inside these borders. I've been using the crop_resized and composite methods of the RMagick library and it works perfectly when the overlay image is larger than the border into which I'm placing it. The trouble I'm having is when I encounter a smaller image, such as the following:
I'd like to know how to resize (shrink) the border image so that the dimensions of the blank center part are similar (or the same) as the smaller image, so then I can just place the smaller image into this blank portion.
I was thinking that I might be able to find the difference between the small image and the blank part of the border image as a percentage, and then shrink the border image by this value. So in this example, the white part of the border image is 577x428 and the smaller image is 288x204, so the difference in size is (204/428)*100 =~ 47.66% (I can either use the x-values or the y-values). But I'm not sure if this is the best way to solve this problem, so I figured I'd see if anyone here has better suggestions. Thanks in advance.
Adam
I have a few border images, such as the following:
and a large number of images that I need to place inside these borders. I've been using the crop_resized and composite methods of the RMagick library and it works perfectly when the overlay image is larger than the border into which I'm placing it. The trouble I'm having is when I encounter a smaller image, such as the following:
I'd like to know how to resize (shrink) the border image so that the dimensions of the blank center part are similar (or the same) as the smaller image, so then I can just place the smaller image into this blank portion.
I was thinking that I might be able to find the difference between the small image and the blank part of the border image as a percentage, and then shrink the border image by this value. So in this example, the white part of the border image is 577x428 and the smaller image is 288x204, so the difference in size is (204/428)*100 =~ 47.66% (I can either use the x-values or the y-values). But I'm not sure if this is the best way to solve this problem, so I figured I'd see if anyone here has better suggestions. Thanks in advance.
Adam