How do I load an image from url, scale but keep the ratio?

0 favourites
  • 8 posts
  • Hey, right now I am using the load image from url event with keep current size. Is there any way to scale the images in such a way that they get parsed with their ratio intact? (So for ex say my image container is 100x50, I put in an 50x10 image, I'd like it to be fit as much as possible which would be 100x20 in this example)

  • bump

  • This could be complicated but a workaround way could be maybe to use conditions to determine which is more out of the proportion you need, width or height. Also have it update a variable of the original size. Resize the image to fit which ever axis was too large by the most (either width or height) use the original value and the new value to work out the percentage to reduce/enlarge the other axis.

    I am only new to this and I am finding there is usually an easier way to everything but maybe this might help.

  • This could be complicated but a workaround way could be maybe to use conditions to determine which is more out of the proportion you need, width or height. Also have it update a variable of the original size. Resize the image to fit which ever axis was too large by the most (either width or height) use the original value and the new value to work out the percentage to reduce/enlarge the other axis.

    I am only new to this and I am finding there is usually an easier way to everything but maybe this might help.

    I did not think of this, and is in fact complicated but helpful (I like a challenge ^^) Let's see how far this will get me

  • Okay, for the life of ..erm everything? x'D.. I cannot seem to figure this out... Anybody who wants to help a hand: feel free to..

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I now have the following events:

    CONDITION

    sprite.Width > width (set to width of loaded image)

    set height to round(imageDisplay.Height*(width/ImageDisplay.Width))

    set sprite.Width to width (set to width of loaded image)

    CONDITION

    sprite.Height > height (height of loaded image)

    set width to round(imageDisplay.Width*(height/imageDisplay.Height))

    set sprite.Height to height (of loaded image)

    However this does not resize (but when alerted gives correct sizes back).. What could be the issue of this?

    If needed I am able to supply an capx file (through pm)

  • Do people overlook this thread or does nobody know? :p

  • Why don't you do a small test capx and uploaded it here. Not your full capx. Just a tester because Folks are busy and haven't the time to create a mock up to play around with. You might get more nibbles. This isn't a common thing that people play around with.

    I know ashley did a tutorial on this awhile back (i think).

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)