21492 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 836 Views |
-
Solved: Reusing image file from Image.SetWidth

22 July 2010 at 9:56pm Last edited: 22 July 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?
-
Re: Solved: Reusing image file from Image.SetWidth

22 July 2010 at 10:10pm
doh, I read through the source code, it was because '?flush=1' was in the URL
-
Re: Solved: Reusing image file from Image.SetWidth

4 August 2010 at 9:25am Last edited: 4 August 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..Apartments.php
<?php
class ApartmentsPage extends Page {
static $db = array();
static $has_one = array();function Galleria() {
$object = new stdClass();
$path="../assets/Appartamenti/".$this->Title."/";
if ($handle = opendir($path)){
$path = substr($path,3);
$i=0;
while(false !== ($file = readdir($handle))) {
if(strpos($file,"jpg")!=false){
$object->$i = File::find($path.$file);
$i++;
}
}
}
return $object;
}
}
class ApartmentsPage_Controller extends Page_Controller {
}
?>ApartmentsPage.ss
<% control Galleria %>
<span style="float: left;padding: 3px;margin-bottom: 3px;"><a href="$URL">
<% control CroppedImage(100,100) %>
<img src="$URL" />
<% end_control %>
</a></span>
<% 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.. -
Re: Solved: Reusing image file from Image.SetWidth

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."')");
| 836 Views | ||
|
Page:
1
|
Go to Top |


