_validateSize($width); $height = $this->_validateSize($height); // $externalResizer = $this->_testForExternalResizer(); // switch ($externalResizer) { switch ($this->_use_resizer) { case 'IM': $this->_resizeIM($fullPath, $width, $height, $iconName); break; case 'GD': $this->_resizeGD($fullPath, $width, $height, $iconName); break; } } function _testForExternalResizer() { $result = `which convert`; if (!empty($result)) { return 'IM'; } if (extension_loaded('gd')) { return 'GD'; } return false; } function _validateSize($size) { $size = intval($size); if (empty($size)) { $size = $this->maxSize; } return $size; } function _getNewSize($fullPath, $width, $height) { list($oldWidth, $oldHeight, $type, $attr) = getimagesize($fullPath); if (($oldWidth / $oldHeight) >= ($width / $height)) { $newx = $width; $widn = $oldWidth/$width ; $newy = floor($oldHeight / $widn); } else { $widn = $oldHeight/$height; $newx = floor( $oldWidth / $widn); $newy = $height; } return array("width" => $newx, "height" => $newy); } function _resizeGD($fullName, $width, $height, $iconFullName) { $size = $this->_getNewSize($fullName, $width, $height); $newx = $size['width']; $newy = $size['height']; list($oldWidth, $oldHeight, $imgType, $attr) = getimagesize($fullName); $destimg = imagecreatetruecolor($newx, $newy); if ($imgType == 1) { $sourceimg = imagecreatefromgif ($fullName); } elseif ($imgType == 2) { $sourceimg = imagecreatefromjpeg ($fullName); } elseif ($imgType == 3) { $sourceimg = imagecreatefrompng ($fullName); } if ($gdver == 1) { imagecopyresized($destimg, $sourceimg, 0, 0, 0, 0, $newx, $newy, $oldWidth, $oldHeight); } else { @imagecopyresampled($destimg, $sourceimg, 0, 0, 0, 0, $newx, $newy, $oldWidth, $oldHeight); } if ($imgType == 1) { imagegif($destimg, $iconFullName, $this->quality); } elseif ($imgType == 2) { imagejpeg($destimg, $iconFullName, $this->quality); } elseif ($imgType == 3) { imagepng($destimg, $iconFullName, $this->quality); } return true; } function _resizeIM($fullName, $width, $height, $iconFullName) { $r = "convert -size ".$width.'x'.$height." '$fullName' -resize ".$width.'x'.$height." +profile \"*\" '$iconFullName'"; $out = shell_exec($r); // FileLogger('/tmp/_resize_log.txt', array($r, implode("\n", GetBacktrace()))); // `$r`; return true; } }