PHPMaker automatic thumbnail creation

By | 18 May, 2011

To create a thumbnail to go along with the image you upload to the DB using PHPMaker, you do something like this:

For the sake of simplicity, let’s assume you have two directories:

– “imgs_sessoes” – for all the regular size images

– “imgs_sessoes_tn” – for the thumbnails

After configuring PHPMaker to upload, and resize if you want, the images, you go to Server Events/Client Scripts, item Row_Inserting and add:
function Row_Inserting(&$rs) {
$file=$rs[‘ficheiro’];
$this->ficheiro->Upload->ResizeAndSaveToFile(100, 100, 80, “imgs_sessoes_tn/”, $file, TRUE);
return TRUE;
}

Change your image field as appropriate (mine is called “ficheiro”)

NOTE – ResizeAndSaveToFile() takes 6 arguments: width, height, quality, directory, filename, and boolean for overwrite.

To delete thumbnaill along with regular image, ad in Row_Deleting:

function Row_Deleting(&$rs) {
$filename=$rs[‘ficheiro’];
@unlink(“imgs_sessoes_tn/”.$filename);
return TRUE;
}

NOTE – Again, notice the name of the field.