Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

SetWidth works, resize doesn't?


Go to End


17 Posts   5755 Views

Avatar
ttyl

Community Member, 114 Posts

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?

Avatar
Juanitou

Community Member, 323 Posts

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

Avatar
ttyl

Community Member, 114 Posts

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 GD

Trace

* 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

Avatar
Juanitou

Community Member, 323 Posts

12 November 2009 at 11:20am

I’m confused too!!! I’m getting ‘Missing argument 1 for Image::SetSize()’.

Avatar
ChrisBryer

Community Member, 95 Posts

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

Avatar
patjnr

Community Member, 102 Posts

12 November 2009 at 8:57pm

Edited: 12/11/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

http://doc.silverstripe.org/doku.php?id=recipes:imageupload

Avatar
biapar

Forum Moderator, 435 Posts

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

Avatar
ttyl

Community Member, 114 Posts

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...

Go to Top