Pagesetter » Image Resize Hack

Information

This hack will automatically resize images that were uploaded using an image upload field. Instead of creating only one thumbnail also the original image will be resized. So this can help you saving webspace. Credits: apollo13

Installation

=========================
changes in pnimageapi.php
=========================

insert after:

Code

$ok =  pnModAPIFunc( 'pagesetter', 'image', 'createThumbnailFromGD',
array('image' => $im,
'thumbnailFilePath' => $args['thumbnailFilePath']) );
the following code:

Code

$ok =  pnModAPIFunc( 'pagesetter', 'image', 'createThumbnailFromGD',
array('image' => $im,
'thumbnailFilePath' => $args['imageFilePath'],
'thumbnailsize' => 200) ); //define your imagesize here
Altered by VideoKid

Additionally for smaller images I changed it to:

Code

list($width,$height)=getimagesize($im);
  $max = "480"; //define your imagesize here
  if( ($width > $max) || ($height > $max) ){

  $ok =  pnModAPIFunc( 'pagesetter', 'image', 'createThumbnailFromGD',
            array('image' => $im,
                  'thumbnailFilePath' => $args['imageFilePath'],
                  'thumbnailsize' => $max) );
  }
insert after:

Code

$thumbnailSize = pnModGetVar('pagesetter', 'thumbnailsize');
$thumbnailSize = 100;
the following code:

Code

if ($args['thumbnailsize'])
{
$thumbnailSize =$args['thumbnailsize'];
}
======================
changes in pneditapi
======================
insert after:

Code

$ok = pagesetterCreateThumbnail($uploadFilePath, $thumbnailFilePath, $uploadInfo['type']);
if ($ok === false)
return false;
insert the following code:

Code

if ($fieldData)
{        
$newfile=$uploadDir . '/' .$uploadFilename;
$image_info = getimagesize($newfile) ;
$uploadInfo['type']=$image_info['mime'];
$uploadInfo['size']=filesize($newfile);
$fieldData = $uploadInfo['type']  . '|' . $uploadInfo['size'] . '|' . $uploadFilename  . '|' . $uploadInfo['name'];
}

Commentaren

herr.vorragend
20 okt 2006

Could the changes in pneditapi be integrated in the cvs of pagesetter? Perhaps for a future release?

icozip
24 mei 2007

Does this resize all images or just the ones that are greater than 200px (or whatever 'thumbnailsize' is set to?

Also, does the code for pneditapi go after the bracket following "return false; }" or inside it?

Wendell
05 sep 2009

Great hack, but all images are resized to the specified size, even if they are already smaller than that. Could a conditional be setup to check the image's size and then only resize it if it is bigger than the specified size?

Alleen ingelogde gebruikers kunnen commentaar plaatsen Inloggen / aanmelden