I'm building a little photography portfolio site and I'm running into a question with image->size(). For most applications, the sizing to fit and center-crop is great, but for this site, I want to have a maximum width and maximum height, so that if the photo is narrower than the specified size, it gets smaller and has space on the sides, and if it's shorter, it gets space on the top and bottom.
In other words, I'm looking to size the image such that it never gets cropped; you see the whole image even if it means making it smaller. Is there a way to do that with size()?
2 replies to this topic
#2
Posted 08 April 2012 - 02:27 AM
You would have to write some logic to check the width and height using $image->width() and $image->height() to see which side you want to scale it down on, but then I think it's just a case of using $image->size() and only putting in the width or height
For exams I think I you had an image that was landscape and you wanted to scale to a width of 400px you should be able to do $image->size(400,0) and to scale by height only switch the numbers around.
This is all off the top of my head but I'm pretty sure that setting 0 as one of the dimensions just let's PW work out that other dimension for you.
Was that what you were after?
For exams I think I you had an image that was landscape and you wanted to scale to a width of 400px you should be able to do $image->size(400,0) and to scale by height only switch the numbers around.
This is all off the top of my head but I'm pretty sure that setting 0 as one of the dimensions just let's PW work out that other dimension for you.
Was that what you were after?
#3
Posted 08 April 2012 - 02:47 PM
Ah yes, that's what I needed! It turns out $image->width() and $image->height() are actually rendering functions, so I was able to just do this:
$mainimage = $page->image;
if($mainimage->width >= $mainimage->height) {
echo '<img src="' . $page->image->width(768)->url . '" alt="' . $page->title . '" id="displayimg" />';
} else {
echo '<img src="' . $page->image->height(575)->url . '" alt="' . $page->title . '" id="displayimg" />';
};
Also tagged with one or more of these keywords: solved, image, crop
Community Support →
Modules/Plugins →
Module/Plugin Development →
Add pixlr editStarted by Galaxy, 14 May 2013 |
|
|
||
Community Support →
Getting Started →
Fixed image sizeStarted by Eltom, 03 May 2013 |
|
|
||
Community Support →
General Support →
Image orientation on upload.Started by Ronnie, 04 Apr 2013 |
|
|
||
Community Support →
General Support →
Calling an image field in a templateStarted by cmscritic, 03 Apr 2013 |
|
|
||
Community Support →
Getting Started →
Uploading a new photo to a member profile avatar field?Started by FuturShoc, 07 Mar 2013 |
|
|
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













