I check the image dimensions to see if I need to resize by height or width (in your example image, you'd want to fit the image by its width.) Then I call one of the following handlers. The params are:
- pObj = control reference; name or ID or long ID, etc.
- pOrigImgHeight = the formattedHeight of the image
- pOrigImgWidth = the formattedWidth of the image
Code: Select all
on resizeToHeight pObj,pOrigImgHeight,pOrigImgWidth
put (the height of this cd)/pOrigImgHeight into tRatio
set the rect of pObj to 0,0,(pOrigImgWidth * tRatio),(pOrigImgHeight * tRatio)
end resizeToHeight
on resizeToWidth pObj,pOrigImgHeight,pOrigImgWidth
put (the width of this cd)/pOrigImgWidth into tRatio
set the rect of pObj to 0,0,(pOrigImgWidth * tRatio),(pOrigImgHeight * tRatio)
end resizeToWidth
This positions the resized image at the top left of the card, which in my case is where I wanted it. If that isn't where you want it, you can move the resized image to its original top left, or to the card loc, or wherever you need it. Or you could adjust the handlers to add the new widths and heights to the original image rect.
It wouldn't be difficult to pass another parameter specifying whether to resize by height or width, and then this could be a single handler instead of two.