Jump to:

22976 Posts in 11620 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

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 2 3 4 5
Go to End
Author Topic: 4390 Views
  • Craftnet
    Avatar
    Community Member
    58 Posts

    Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width Link to this post

    @Liam
    I added your question to topic.
    Maybe more people look in this topic and someone solve your issue

  • thi3r
    Avatar
    Community Member
    25 Posts

    Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width Link to this post

    for some reason the function call doesn't work within the loop when used with $Up...
    so here is an alternative... maybe not the best solution but seems to work this time.

    Add this to your controller:

    public function GetImages()
       {
          $images = $this->Images();
          $parsedImages = new ArrayList();
          
          foreach ($images as $img)
          {
             if($img->getWidth() > 800) $img->LargerThan800 = true;
             $parsedImages->push($img);
          }
          
          return $parsedImages;
       }

    and use it like this in your template

    <% loop $GetImages %>
             <% if $LargerThan800 %>
                <a href="$SetWidth(800).URL" class="itemPhotos <% if MultipleOf(5) %> itemPhotosLast <% end_if %>" title="$Title">$CroppedImage(158,158)</a>
             <% else %>
                $Width
             <% end_if %>
             
          <% end_loop %>

    basically it goes through the attached images and add a variable if larger than 800px which is then available in the template. You can do other test in the same way if needed.

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width Link to this post

    Yup that works.

    Thanks for taking the time to look into it and get a working solution, even after all this time.

    I changed <% loop $GetImages %> to <% loop GetImages %> for it to work in case anybody following this topic needs it.

    4390 Views
Page: 1 2 3 4 5
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.