Resize image downloaded from a RSS feed

Hi,

I’m implementing some of the corona business app’s code in my new app. Everything works fine but I need to resize the image downloaded from the feed and I don’t know how to do so. Can somebody help me? I’d be very glad if you could help me come across that.

Thanks!

Do you need to resize it or scale it to fit a space?  They may seem like the same question, but they are not.  Scaling is really simple, but you have to think about the space you have.  Do you need make the images fit based on height or based on width?  In other words you  have to ask yourself, It has to be X pixels wide and I don’t care how tall it is  or It has to be Y pixels high and I don’t care how wide it is.  Of course, you may have to do both to get it fit with in both dimensions.

Lets assume you want to use a tableView that has 100px high rows and you have something like:

local myImage = display.newImage(“mydownloaded.jpg”)

local s = 100 / myImage.height

myImage:scale( s, s )

If you need to constrain on the width:

local s = 100 / myImage.width

myImage:scale( s, s )

If you need to do both:

local s = 100 / myImage.height

if ( s * myImage.width ) > 100 then

     s = 100 / myImage.width

end

myImage:scale( s, s )

Rob

Looking to your answers makes me feel like I’ve formulated mistakenly my question. Lets see. When the feed is downloaded the entries are populated into table view rows. And then when tapping a row, a new scene comes up showing a webview with the text from the feed and an image that may contain the feed. The text is aligned perfectly along the screen’s width, but the image is oversized on its width. That’s what I want to adjust. I think now is better explained, let me know.

Lots of thanks

Actually resizing the image is going to be tough.  You have to load the image, then use some of the image capture/save functions and I don’t have a lot of experience with it.

The other thing you can do is to specify the width and height on the img tag in your HTML for the size you want the image to be and let the browser resize it.  You can use math from above, once you know the scale to calculate the new width and height to provide to the img tag.

local imgWidth = myImage.width * s

local imgHeight = myImage.height * s

print(’<img src="’ … filename … ‘" width=’ … imgWidth … ’ height=’ … imgHeight … ’ />’)

Thanks for your help Rob. I’ll give it a look and let you know how it worked!

Do you need to resize it or scale it to fit a space?  They may seem like the same question, but they are not.  Scaling is really simple, but you have to think about the space you have.  Do you need make the images fit based on height or based on width?  In other words you  have to ask yourself, It has to be X pixels wide and I don’t care how tall it is  or It has to be Y pixels high and I don’t care how wide it is.  Of course, you may have to do both to get it fit with in both dimensions.

Lets assume you want to use a tableView that has 100px high rows and you have something like:

local myImage = display.newImage(“mydownloaded.jpg”)

local s = 100 / myImage.height

myImage:scale( s, s )

If you need to constrain on the width:

local s = 100 / myImage.width

myImage:scale( s, s )

If you need to do both:

local s = 100 / myImage.height

if ( s * myImage.width ) > 100 then

     s = 100 / myImage.width

end

myImage:scale( s, s )

Rob

Looking to your answers makes me feel like I’ve formulated mistakenly my question. Lets see. When the feed is downloaded the entries are populated into table view rows. And then when tapping a row, a new scene comes up showing a webview with the text from the feed and an image that may contain the feed. The text is aligned perfectly along the screen’s width, but the image is oversized on its width. That’s what I want to adjust. I think now is better explained, let me know.

Lots of thanks

Actually resizing the image is going to be tough.  You have to load the image, then use some of the image capture/save functions and I don’t have a lot of experience with it.

The other thing you can do is to specify the width and height on the img tag in your HTML for the size you want the image to be and let the browser resize it.  You can use math from above, once you know the scale to calculate the new width and height to provide to the img tag.

local imgWidth = myImage.width * s

local imgHeight = myImage.height * s

print(’<img src="’ … filename … ‘" width=’ … imgWidth … ’ height=’ … imgHeight … ’ />’)

Thanks for your help Rob. I’ll give it a look and let you know how it worked!