21492 Posts in 5783 Topics by 2621 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 2764 Views |
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

26 July 2012 at 6:28pm
@Liam
Use only $Width -
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

27 July 2012 at 12:22am
like @Craftnet said, you don't need $Image since the loop tag places you in the image scope.
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

27 July 2012 at 2:37am Last edited: 27 July 2012 2:56am
Oh. Duh.
One last thing.
Is there no way to compare less than in the template logic?
Or is there an image function I can use in the template that only resizes the image if it's larger than a certain width?
In the template, if I have an image over 800px I want to resize it to 800px, SetWidth(800), but if it's smaller, than display normal.
Or do I have to extend the image class and do it from there?
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

27 July 2012 at 5:03am
never tried greater or smaller than operator in templates, but I had in mind than SS3 template logic is now better. Did you try <% if $Image.Width < 800 %> or similar?
Otherwise you might be able to create a test function in your controller that returns a boolean, with something like this:
<% if $isBigger($Image.Width, 800) %>you can extend the Image class but it doesn't seem necessary here
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

27 July 2012 at 5:43am
Ya I was trying <% if $Width < 800 %> while in the Images scope but it throws an error and it's the less than operator that is causing it. $Width returns proper value.
I didn't see anything in the template docs about < > so I don't think it's supported. Oh well.
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

27 July 2012 at 9:01am
try using this in the template then:
<% if $greaterThan($Width, 800) %>
<% end_if %>
with this in the controller
public function greaterThan($value, $reference)
{
if ($value > $reference) return true;
else return false;
}there might be better solutions, but this could work...
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

27 July 2012 at 12:50pm
Yup this looks like it does the job.
I'll be sure to note that less/greater than operators don't work in templates.
Cheers,
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

27 July 2012 at 1:10pm
Actually upon further inspection this always returns false.
I'll play around with it and let you know what I find.
Thanks.
| 2764 Views | ||
| Go to Top | Next > |



