22
Mar
7
Resizing an image in a custom <img> tag
You can resize images from within the template very easily. But sometimes you need to resize it and just use the URL value, something you can't do by calling the resize on the variable directly (e.g. $Image1.CroppedImage(200,200). This is how we would create a cropped resize of it and still be able to use just the URL, allowing a custom <img> tag.
You can also use these other GD functions in a control block:
About the Author
Name: Aram
Comments (7)
-
Thank-you, thank-you, thank-you! We'd been struggling with dataobject_manager...the thing from Uncle Cheese that is as big a blessing as it is a curse...and couldn't figure out how to resize images we were uploading through it. Fixed our problem! Thanks, again!
Posted by Jeremy Edgell, 16/04/2010 8:08pm (3 months ago)
-
... without the slashes of course...
Posted by yurigoul, 28/10/2009 10:49am (9 months ago)
-
To create a lightbox I used this code, based on your example:
<% control MainImage %>
<% control SetHeight(600) %>
<a href=\"$URL\" <% end_control %> title=\"$Title\" rel=\"lightbox\">
<% control CroppedImage(580, 200) %>
<img src=\"$URL\"<% end_control %> alt=\"$Title\" />
</a>
<% end_control %>
Returns:
<a href=\"/s/assets/Uploads/_resampled/SetHeight600-bloem2.jpg\" title=\"bloem2\" rel=\"lightbox\">
<img src=\"/s/assets/Uploads/_resampled/croppedimage580200-bloem2.jpg\" alt=\"bloem2\" />
</a>
Is there any reason why I should not do this?Posted by yurigoul, 28/10/2009 10:47am (9 months ago)
-
Any responses to Patrick? I need to refer to the $Title of the original image in the image tag - is there a way of accessing that? I see that setWidth doesn't return the parent attributes...
Posted by Martin, 06/10/2009 9:39am (10 months ago)
-
how do i get the title of the image
Posted by patrick, 05/10/2009 8:22am (10 months ago)
-
for basic size manipulation like a fixed width you can also use smth link...
$Photo.SetWidth(50)Posted by lukas, 22/07/2009 8:02am (1 year ago)
-
Here some more stuff:
GD functions you can use in PHP
This is a list of methods you can call on your image object.
resize(width,height)
Very basic resize, just skews the image if necessary
resizeRatio(width,height)
Resizes an image with a maximum width and height - a useful function
paddedResize(width,height)
Adds additional padding if necessary after resizing to width height.
croppedResize(width,height)
Crops the image from the centre, to the given width and height.
resizeByHeight(height)
Maximum height the image resizes to, keeps proportion so width is flexible.
resizeByWidth(width)
Maximum width the image resizes to, keeps proportion so height is flexible
greyscale(r,g,b)
You pass the specific red green blue colour values to alter image channels ===
getHeight
Returns the height of the image.
getWidth
Returns the width of the image
getOrientation
(from 2.3) Returns a class constant: ORIENTATION_SQUARE or ORIENTATION_PORTRAIT or ORIENTATION_LANDSCAPE
Posted by SalvaStripe, 30/04/2009 5:17am (1 year ago)
RSS feed for comments on this page RSS feed for all comments