21278 Posts in 5728 Topics by 2599 members
| Go to End | Next > | |
| Author | Topic: | 3353 Views |
-
SetWidth works, resize doesn't?

11 November 2009 at 9:57am
new to ss and I find this very odd, hoping somebody can point me in the right direction.
when I do this:
$myImage.SetWidth(150)
it outputs the image with the set width as expected - very cool.
however, when I do this:
$myImage.resize(150, 150)
I get "(150, 150)" on the page. am I doing something wrong?
-
Re: SetWidth works, resize doesn't?

11 November 2009 at 11:33am
Hi!
Wrong syntax, use instead: $myImage.SetSize(150,150) (http://doc.silverstripe.org/doku.php?id=image)
Hope it helps,
Juan -
Re: SetWidth works, resize doesn't?

12 November 2009 at 3:26am
that causes everything to break...very confused.
Source
173
174 public function SetWidth($width) {
175 return $this->getFormattedImage('SetWidth', $width);
176 }
177
178 public function SetHeight($height) {
179 return $this->getFormattedImage('SetHeight', $height);
180 }
181
182 public function SetSize($width, $height) {
183 return $this->getFormattedImage('SetSize', $width, $height);
184 }
185
186 /**
187 * Resize this Image by width, keeping aspect ratio. Use in templates with $SetWidth.
188 * @return GDTrace
* Image->SetSize()
* call_user_func_array(Array,Array)
Line 408 of ViewableData.php
* ViewableData->XML_val(SetSize,,1)
Line 182 of .cache.Applications.MAMP.htdocs.ss.themes.tutorial.templates.Layout.FacultyPage.ss
* include(/private/var/folders/C2/C2RzM9F2GDqG5p2gxYQxyE+++TM/-Tmp-/silverstripe-cache-Applications-MAMP-htdocs-ss/.cache.Applications.MAMP.htdocs.ss.themes.tutorial.templates.Layout.FacultyPage.ss)
Line 354 of SSViewer.php
* SSViewer->process(FacultyPage_Controller)
Line 346 of SSViewer.php
* SSViewer->process(FacultyPage_Controller)
Line 175 of Controller.php
* Controller->handleAction(HTTPRequest)
Line 129 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 122 of Controller.php
* Controller->handleRequest(HTTPRequest)
Line 29 of ModelAsController.php
* ModelAsController->handleRequest(HTTPRequest)
Line 277 of Director.php
* Director::handleRequest(HTTPRequest,Session)
Line 121 of Director.php
* Director::direct(/person/)
Line 118 of main.php -
Re: SetWidth works, resize doesn't?

12 November 2009 at 11:20am
I’m confused too!!! I’m getting ‘Missing argument 1 for Image::SetSize()’.
-
Re: SetWidth works, resize doesn't?

12 November 2009 at 3:13pm
i havent had much luck with using 1 method to proportionately resize an image but you can check the orientation in the template, and depending on the orientation either call setHeight or setWidth.
hope it helps
-
Re: SetWidth works, resize doesn't?

12 November 2009 at 8:57pm Last edited: 12 November 2009 8:59pm
With my experience working with images the best way is to make use of the php gd function by extend the image class.
1. create a php file called FittedImage.php
<?php
class FittedImage extends Image {function generateMainImage($gd) {
$gd->setQuality(80);
return $gd->resizeRatio(370,240);
}function generateThumbImage($gd) {
$gd->setQuality(80);
return $gd->resize(120,80);
}}
?>2.
static $has_one = array(
'GalleryImage' => 'FittedImage ',);
3.
in you Template it can be
<img src="$GalleryImage.ThumbImage.URL" />
this will be for the small image which (may be ) on mouseover it displays the MainImage in another div
for the Main image
<img src="$GalleryImage.MainImage.URL" />
let me know if you need a URL for the site where this functionality is in place.
hope this makes sense
this is clearly explained here
-
Re: SetWidth works, resize doesn't?

12 November 2009 at 11:19pm
Hi,
I use the same method of Pat jnr...
class Product extends Page {
static $db = array(
'DescrBreve' => 'Text',
'Evidence' => 'Boolean'
);static $has_one = array(
'ProdottoImage1' => 'Product_Image',
)etc...
class Product_Image extends Image {
function generateCroppedImage($gd) {
$gd->setQuality(90);
return $gd->croppedResize(300,130);
}}
theni into template ( .ss file )
$ProdottoImage1.CroppedImage
Bye
-
Re: SetWidth works, resize doesn't?

13 November 2009 at 10:20am
I understand I can extend my classes, which is why I like silverstipe thus far. but should I view the prebuilt image function as unreliable? as I'm still in my newbie phase are there other types of things I should just write my own functionality for? I'm not sure I want to be getting into any scenarios where example code from tutorials isn't something I can count on...
| 3353 Views | ||
| Go to Top | Next > |



