Jump to content

How to get image scaled down proportionally (given a constraint)


landitus
 Share

Recommended Posts

Is it possible to get an image scaled down proportionally, like for example, I need it to fit in a 400px box (no height constraint). And the images might have different heights that would respond to the given constraint? Right now it seems I need to specify the width and height of the image that it placed, but the problem is I have images of different sizes and proportions.

Link to comment
Share on other sites

You can specify 0 for the width or height to have it be proportional to the other dimension. Or you can just use the width(x) or height(y) functions rather than size(x, y) function. So in your case, I think what you are asking for is this:

$image = $page->image->width(400); 
Link to comment
Share on other sites

Thanks Apeisa, I used it like this

if($image->width > 500) $image = $image->width(500); ?>
<img src="<?php echo $image->url?>" alt="">

but would be very nice to have a maxwidth() in PW

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...