Welcome to Geeklog, Anonymous Monday, November 25 2024 @ 08:22 am EST

Geeklog Forums

geeklog resize with gdlib


Status: offline

raffles

Forum User
Newbie
Registered: 06/03/03
Posts: 11
Hi!

If you want to have geeklog resizing pics with gdlib (and neither with imagemagick nor netpbm) here is how
Just a quick hack that works probably not just for me - maybe this could go into the next version?

open the file /system/classes/upload.classes.php and look for the lines:
Text Formatted Code

***
            } else {
                // use netpm
***

and exchange them with:

***
} elseif ($this->_imageLib == 'netpbm') {
                // use netpm
***

then go some lines below where  it says:

***
$returnChmod = true;
***

leave the line as it is and add the following above:

***
} elseif ($this->_imageLib == 'gdlib2') {  // if set to gdlib2
              if ($this->_keepOriginalImage) {
                    $filename = $this->_fileUploadDirectory . '/'. $this->_getDestinationName ();
                    $lFilename_large = substr_replace ($this->_getDestinationName (), '_original.', strrpos ($this->_getDestinationName (), '.'), 1);
                    $lFilename_large_complete = $this->_fileUploadDirectory. '/' .  $lFilename_large;
                    if (!copy ($filename, $lFilename_large_complete)) {
                        $this->_addError ("Couldn't copy $filename to $lFilename_large_complete.  You'll need to remove both files.");
                        $this->printErrors ();
                        exit;
                    }
              }
              $file=$this->_fileUploadDirectory . '/' . $this->_getDestinationName();
              $old_picture  = imagecreatefromjpeg($file);
              $new_picture = imagecreate($newwidth, $newheight);
              if (!imagecopyresampled($new_picture, $old_picture, 0, 0, 0, 0, $newwidth, $newheight, $imageInfo['width'], $imageInfo['height']))
                $retval=1;
              if (!imagecreatetruecolor($new_picture, $this->_fileUploadDirectory . '/' . $this->_getDestinationName()))
                $retval=2;
            }
            else {       // use gdlib1
              if ($this->_keepOriginalImage) {
                    $filename = $this->_fileUploadDirectory . '/'. $this->_getDestinationName ();
                    $lFilename_large = substr_replace ($this->_getDestinationName (), '_original.', strrpos ($this->_getDestinationName (), '.'), 1);
                    $lFilename_large_complete = $this->_fileUploadDirectory. '/' .  $lFilename_large;
                    if (!copy ($filename, $lFilename_large_complete)) {
                        $this->_addError ("Couldn't copy $filename to $lFilename_large_complete.  You'll need to remove both files.");
                        $this->printErrors ();
                        exit;
                    }
              }
              $file=$this->_fileUploadDirectory . '/' . $this->_getDestinationName();
              $old_picture  = imagecreatefromjpeg($file);
              $new_picture = imagecreate($newwidth, $newheight);
              if (!imagecopyresized($new_picture, $old_picture, 0, 0, 0, 0, $newwidth, $newheight, $imageInfo['width'], $imageInfo['height']))
               $retval=3;
              if (!imagejpeg($new_picture, $this->_fileUploadDirectory . '/' . $this->_getDestinationName()))
               $retval=4;
            }

            if ($retval > 0) {
                if ($this->_imageLib == 'imagemagick') {
                    $this->_addError('Image, ' . $this->_currentFile['name'] . ' had trouble being resized: ' . $mogrify_output[0]);
                } elseif ($this->_imageLib == 'netpbm') {
                    $this->_addError('Image, ' . $this->_currentFile['name'] . ' had trouble being resized: ' . $netpbm_output[0]);
                } else {
                    $this->_addError('Image, ' . $this->_currentFile['name'] . ' had trouble being resized using '.$this->_imageLib.' - Errorcode' . $retval);
                }
                $this->printErrors();
                exit;
            } else {
                    $this->_addDebugMsg('Image, ' . $this->_currentFile['name'] . ' was resized from ' . $imageInfo['width'] . 'x' . $imageInfo['height'] . ' to ' . $newsize);
            }
        }
***


Set the value $_CONF['image_lib'] in config.php to either "gdlib1" or gdlib2 depending on your servers version. "gdlib > 2" uses resample which produces better quality) So try gdlib2 first - if this does not work - try gdlib1
(it would be possible to find out the right verison in the script but I don't like it - see the comments on www.php.net about imagecreatetruecolor)

have fun

BTW: how to get rid of the blue frame around the smaller picture when it is a link to the original? Where to put the border='0' ?
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
The upload class in CVS already supports gdlib ...

bye, Dirk
 Quote

Status: offline

raffles

Forum User
Newbie
Registered: 06/03/03
Posts: 11
before or after my post? :-)
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Before your post, I'm afraid. Rob Coenen contributed the code for this some time ago.

bye, Dirk
 Quote

Status: offline

raffles

Forum User
Newbie
Registered: 06/03/03
Posts: 11
OK ... wasn't asking cause I need the reputation (I don't care). Just wondered whether you are so fast ...

regards
Daniel
 Quote

All times are EST. The time is now 08:22 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content