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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Solved: Reusing image file from Image.SetWidth

Go to End

4 Posts   1240 Views


Community Member, 59 Posts

22 July 2010 at 9:56pm

Edited: 22/07/2010 10:11pm

Hi All,

I'm creating a basic gallery for a site, where the admin of the site just uploads images into a specific folder, and they're displayed on a page. I don't the site owner to have to do anything else.

I've attempted using the Image.SetWidth to generate thumbnails, that works okay and a resized image is saved in assets which is fine. I then expect it to reuse it, but it doesn't, it regenerates the thumbnail everytime the page is viewed. The test server I'm using is slowing down to a crawl every time I view the page, the final site will be on shared hosting as well, and I don't want this page to interrupt other clients. Is there a way to tell it to look for an already resized version before regenerating thumbnails?


Community Member, 59 Posts

22 July 2010 at 10:10pm

doh, I read through the source code, it was because '?flush=1' was in the URL


6 Posts

4 August 2010 at 9:25am

Edited: 04/08/2010 9:27am

Hi StuM,
I'm very new to SS and I have implemented a basic image gallery similiar to your.
It works well and I would like to share my code with you. I don't know if my code is ok.. mabe could be better..


class ApartmentsPage extends Page {
	static $db = array();
	static $has_one = array();

	function Galleria() {
		$object = new stdClass();
		if ($handle = opendir($path)){
			$path = substr($path,3);
			while(false !== ($file = readdir($handle))) {
					$object->$i = File::find($path.$file);
		return $object;

class ApartmentsPage_Controller extends Page_Controller {

<% control Galleria %>
	<span style="float: left;padding: 3px;margin-bottom: 3px;"><a href="$URL">
	<% control CroppedImage(100,100) %>
		<img src="$URL" />
	<% end_control %>
<% end_control %>

I'm "reading" all jpg files inside Assets/Appartamenti/<Page Title>/ , creating the object of the reading result and passing it to the control on the ss template.
Don't know if is ok or not... but it works..


6 Posts

4 August 2010 at 10:03pm

Just learned something new and definitely better:

return DataObject::get("Image", "ClassName <> 'Folder' AND ParentID = (SELECT ID FROM File WHERE ClassName = 'Folder' AND Name = '".$this->Cartella_Immagini."')");