Ejemplo n.º 1
0
 function _imageResizeGif($file, $output, $origwidth, $origheight, $width, $height, $cropX = 0, $cropY = 0)
 {
     if (!function_exists('imagegif') && (!function_exists('imagecreatefromgif') || !function_exists('imagepng'))) {
         return false;
     }
     $canGif = true;
     // more robust gif support check for PHP > 4.0.2
     if (function_exists('imagetypes')) {
         if (!(imagetypes() & IMG_GIF)) {
             $canGif = false;
             if (!(imagetypes() & IMG_PNG)) {
                 return false;
             }
         }
     }
     //$extension = strrchr(strtolower($file),'.');
     // check and set required memory to process this image
     if (!$this->_setMemoryForImage($file)) {
         return false;
     }
     //create the blank limited-palette image
     if (!($base_image = $this->_imageCreateBase($width, $height))) {
         return false;
     }
     // get the image pointer to the original image
     if (!($imageToResize = @imagecreatefromgif($file))) {
         return false;
     }
     if (function_exists('imagecopyresampled')) {
         if (!@imagecopyresampled($base_image, $imageToResize, 0, 0, $cropX, $cropY, $width, $height, $origwidth, $origheight)) {
             @imagecopyresized($base_image, $imageToResize, 0, 0, $cropX, $cropY, $width, $height, $origwidth, $origheight);
         }
     } else {
         @imagecopyresized($base_image, $imageToResize, 0, 0, $cropX, $cropY, $width, $height, $origwidth, $origheight);
     }
     if (!function_exists('imagegif') || !$canGif) {
         $outputFunction = 'imagepng';
         $header = 'Content-type: image/x-png';
         //$output = str_replace($extension, '.png', $output);
     } else {
         $outputFunction = 'imagegif';
         $header = 'Content-type: image/gif';
     }
     $return = false;
     $doIt = true;
     $deleteOrig = false;
     if (empty($output)) {
         header($header, true);
         if (@$outputFunction($base_image)) {
             $return = array($width, $height, $output);
         }
     } else {
         if ($outputFunction == 'imagepng') {
             // extension on the output file must be changed
             //$name = substr($output, 0, strlen($output) - strlen($extension));
             $name = $output . '.png';
             if (file_exists($name)) {
                 $return = false;
                 $doIt = false;
             } else {
                 if ($file == $output) {
                     $deleteOrig = true;
                 }
                 $output = $name;
             }
         }
         $fh = @fopen($output, 'w');
         @fclose($fh);
         if ($doIt) {
             if (@$outputFunction($base_image, $output)) {
                 //image destination
                 if ($outputFunction == 'imagepng') {
                     if ($deleteOrig) {
                         @unlink($file);
                     }
                 }
                 $return = array($width, $height, $output);
                 if (!empty($this->fileCHMOD)) {
                     $fs = new wproFilesystem();
                     $fs->chmod($output, $this->fileCHMOD);
                 }
             }
         }
     }
     @imagedestroy($base_image);
     @imagedestroy($imageToResize);
     return $return;
 }