Jump to:

23376 Posts in 18295 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Creating resized image on upload instead of when you load the template

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

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

Page: 1
Go to End
Author Topic: 1012 Views
  • dendeffe
    Avatar
    Community Member
    135 Posts

    Creating resized image on upload instead of when you load the template Link to this post

    Hi,

    I'm trying to get my custom (resized) image to create the file on upload instead of when you open the template.
    I need this to happen because I'm adding it to the page with JavaScript. Thanks to a lot of help from IRC I tried this:

    http://pastie.org/819190

    I didn't get it working though. Does anyone else have suggestions? Or an alterive idea with the JavaScript?

  • Mo
    Avatar
    Community Member
    505 Posts

    Re: Creating resized image on upload instead of when you load the template Link to this post

    Hi dendeffe,

    I am not sure why javascript would cause an issue? Setting an image size in the template using something like $Img.SetWidth(106) for example, would generate a new image that wil then be referenced in the html dynamically.

    As javascript is generally loaded after a page has loaded, the javascript should then just work with the resized images.

    Maybe it would help if you explain what you are trying to achieve?

    Mo

  • dendeffe
    Avatar
    Community Member
    135 Posts

    Re: Creating resized image on upload instead of when you load the template Link to this post

    I was trying to append an Image from an external JavaScript, which didn't work.

    I've 'solved' it by generating a JavaScript Array with the image names in an included Template. It seems that simply mentioning the file without displaying also does the trick, it just needs to be in a template file.

  • Mo
    Avatar
    Community Member
    505 Posts

    Re: Creating resized image on upload instead of when you load the template Link to this post

    That is pretty much what I would have suggested. You can use the the template methods within your classes as well, they may give you better results.

    Have you looked at: http://doc.silverstripe.org/doku.php?id=image

    Mo

  • dendeffe
    Avatar
    Community Member
    135 Posts

    Re: Creating resized image on upload instead of when you load the template Link to this post

    Ok thanks Mo. What's the advantage of using the template functions over a class function like this?

       function generateSmallThumb($gd) {
          return $gd->resizeRatio(108, 168, true);
       }

  • Mo
    Avatar
    Community Member
    505 Posts

    Re: Creating resized image on upload instead of when you load the template Link to this post

    My instinct would be to say the template methods are written as part of Silverstripe by the Dev's, so are integrated better, in terms of performance.

    Of course, I would like to think that is true, but I can't guarantee it . Also, I believe using the template functions automatically references the resized image back to the source image that you uploaded, where as if you were using gd, you would have to do that yourself. That might not be an issue for you though.

    Not sure that makes sense... Hopefully it does .

    Mo

    1012 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.