Example #1
0
 protected function _thumb($sourceFilename, $targetFilename, $params)
 {
     // recursively create folders
     new Folder(dirname($targetFilename), true);
     // Import phpThumb class
     App::import('Vendor', 'phpthumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     // Configuring thumbnail settings
     $phpThumb = new phpthumb();
     $phpThumb->setSourceFilename($sourceFilename);
     $phpThumb->w = $params['width'];
     $phpThumb->h = $params['height'];
     $phpThumb->setParameter('zc', $params['zoomCrop']);
     $phpThumb->q = $params['quality'];
     $imageArray = explode(".", $source);
     $phpThumb->config_output_format = $imageArray[1];
     unset($imageArray);
     // Setting whether to die upon error
     $phpThumb->config_error_die_on_error = true;
     // Creating thumbnail
     if ($phpThumb->GenerateThumbnail()) {
         if (!$phpThumb->RenderToFile($targetFilename)) {
             trigger_error('Could not render image to: ' . $targetFilename);
         }
     }
 }
Example #2
0
 function render($image, $params)
 {
     //Set defaults
     $path = '';
     $width = 150;
     $height = 225;
     $quality = 75;
     //Extract Parameters
     if (isset($params['path'])) {
         $path = $params['path'] . DS;
     }
     if (isset($params['width'])) {
         $width = $params['width'];
     }
     if (isset($params['height'])) {
         $height = $params['height'];
     }
     if (isset($params['quality'])) {
         $quality = $params['quality'];
     }
     //import phpThumb class
     app::import('Vendor', 'phpthumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     $thumbNail = new phpthumb();
     $thumbNail->src = WWW_ROOT . 'img' . DS . $path . $image;
     $thumbNail->w = $width;
     $thumbNail->h = $height;
     $thumbNail->q = $quality;
     $thumbNail->config_imagemagick_path = '/usr/bin/convert';
     $thumbNail->config_prefer_imagemagick = true;
     $thumbNail->config_output_format = 'jpg';
     $thumbNail->config_error_die_on_error = true;
     $thumbNail->config_document_root = '';
     $thumbNail->config_temp_directory = APP . 'tmp';
     $thumbNail->config_cache_directory = WWW_ROOT . 'img' . DS . 'thumbs' . DS;
     $thumbNail->config_cache_disable_warning = true;
     $cacheFilename = $image;
     $thumbNail->cache_filename = $thumbNail->config_cache_directory . $cacheFilename;
     if (!is_file($thumbNail->cache_filename)) {
         if ($thumbNail->GenerateThumbnail()) {
             $thumbNail->RenderToFile($thumbNail->cache_filename);
         }
     }
     if (is_file($thumbNail->cache_filename)) {
         return $cacheFilename;
     }
 }
Example #3
0
 function index()
 {
     if (count($this->params['pass'])) {
         $src = implode('/', array_slice($this->params['pass'], 1));
         $action = $this->params['pass'][0];
         $phpThumb = new phpthumb();
         $sourceFilename = Configure::read('Resource.media_path') . DS . $src;
         $cacheFilename = md5("{$action}{$src}");
         $phpThumb->src = $sourceFilename;
         $phpThumb->config_cache_directory = Configure::read('Thumb.cache_path') . DS;
         $phpThumb->config_imagemagick_path = Configure::read('Thumb.imagemagick_path');
         $phpThumb->config_prefer_imagemagick = true;
         $phpThumb->config_output_format = 'jpeg';
         $phpThumb->config_error_die_on_error = false;
         $phpThumb->config_document_root = '';
         $phpThumb->config_cache_prefix = '';
         $phpThumb->config_cache_source_enabled = 1;
         $phpThumb->cache_filename = $phpThumb->config_cache_directory . $cacheFilename;
         $phpThumb->config_max_source_pixels = 5000000;
         $phpThumb->sia = implode('_', array_slice($this->params['pass'], 1));
         $thumb_parameters = Configure::read('Thumb.media_parameters');
         if (in_array($action, array_keys($thumb_parameters))) {
             $thumb_vars = $thumb_parameters[$action];
             $phpThumb->cache_filename = $phpThumb->config_cache_directory . $cacheFilename;
             foreach ($thumb_vars as $ti => $thumb_var) {
                 $phpThumb->setParameter($ti, $thumb_var);
             }
             if (file_exists($phpThumb->cache_filename) && filemtime($phpThumb->src) < filemtime($phpThumb->cache_filename)) {
                 $phpThumb->useRawIMoutput = true;
                 $phpThumb->IMresizedData = file_get_contents($phpThumb->cache_filename);
                 $this->set('phpthumb', $phpThumb);
             } elseif ($phpThumb->GenerateThumbnail()) {
                 $phpThumb->RenderToFile($phpThumb->cache_filename);
                 $this->set('phpthumb', $phpThumb);
             } else {
                 die('Error caching thumbnail <pre>' . print_r($phpThumb, true) . '</pre>');
             }
         } else {
             $this->redirect(Configure::read('Resource.media_path') . "/{$src}");
         }
     } else {
         $this->viewPath = 'errors';
         $this->render('not_found');
     }
 }
Example #4
0
 function resize($img, $options, $folder = "", $cache = true)
 {
     $hash = md5($img . serialize($options));
     if (!file_exists($img) || is_dir($img)) {
         $img = PATH_DESIGN . "img" . DS . "nophoto.png";
     }
     $ext = "";
     $phpThumb = new \phpthumb();
     $phpThumb->setSourceFilename($img);
     $phpThumb->setParameter("q", IMAGE_QUALITY_DEFAULT);
     foreach ($options as $key => $value) {
         $phpThumb->setParameter($key, $value);
         if ($key == "f") {
             $ext = $value;
         }
     }
     if ($ext == "") {
         $phpThumb->setParameter("f", "jpg");
         $ext = "jpg";
     }
     if ($folder != "") {
         $tree = explode("/", $folder);
         $path = IMAGE_CACHE_PATH;
         if (is_array($tree)) {
             foreach ($tree as $dir) {
                 $mk = $path . DS . $dir;
                 if (!file_exists($mk)) {
                     mkdir($mk);
                     chmod($mk, 0777);
                 }
                 $path .= DS . $dir;
             }
         }
         $folder .= DS;
     }
     $outputFilename = IMAGE_CACHE_PATH . $folder . $hash . "." . $ext;
     if (!$cache && file_exists($outputFilename)) {
         unlink($outputFilename);
     }
     if (!file_exists($outputFilename)) {
         if ($phpThumb->GenerateThumbnail()) {
             $phpThumb->RenderToFile($outputFilename);
         }
     }
     $res = str_replace(ROOT, "", $outputFilename);
     $res = str_replace(DS, "/", $res);
     return $res;
 }
    @folder - доп папки если необходимо
*/
//return $img;
$replace = array("," => "&", "_" => "=");
$options = strtr($opt, $replace);
$filename = md5($img . $options);
$cache = isset($cache) ? $cache : false;
if ($img[0] != "/") {
    $img = "/" . $img;
}
$nophoto = isset($nophoto) ? $nophoto : "logo.png";
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $img) || is_dir($_SERVER['DOCUMENT_ROOT'] . $img)) {
    $img = "/images/" . $nophoto;
}
require_once dirname(__FILE__) . "/phpthumb.class.php";
$phpThumb = new phpthumb();
$phpThumb->setSourceFilename($img);
$options = explode("&", $options);
foreach ($options as $value) {
    $thumb = explode("=", $value);
    $phpThumb->setParameter($thumb[0], $thumb[1]);
    if ($thumb[0] == "f") {
        $ext = $thumb[1];
    }
}
if ($ext == "") {
    $phpThumb->setParameter("f", "jpg");
    $ext = "jpg";
}
if ($folder != "") {
    $tree = explode("/", $folder);
$tmpImagesFolder = str_replace("assets/images", "", $tmpImagesFolder);
$tmpImagesFolder = explode("/", $tmpImagesFolder);
$ext = strtolower($path_parts['extension']);
$options = 'f=' . (in_array($ext, explode(",", "png,gif")) ? $ext : "jpg&q=96") . '&' . strtr($options, array("," => "&", "_" => "=", '{' => '[', '}' => ']'));
parse_str($options, $params);
foreach ($tmpImagesFolder as $folder) {
    if (!empty($folder)) {
        $cacheFolder .= "/" . $folder;
        if (!is_dir(MODX_BASE_PATH . $cacheFolder)) {
            mkdir(MODX_BASE_PATH . $cacheFolder);
        }
    }
}
$fname_preffix = $cacheFolder . "/" . $params['w'] . "x" . $params['h'] . '-';
$fname = $path_parts['filename'] . "." . substr(md5(serialize($params)), 0, 3) . "." . $params['f'];
$outputFilename = MODX_BASE_PATH . $fname_preffix . $fname;
if (!file_exists($outputFilename)) {
    require_once MODX_BASE_PATH . 'assets/snippets/phpthumb/phpthumb.class.php';
    $phpThumb = new phpthumb();
    $phpThumb->config_temp_directory = $tmpFolder;
    $phpThumb->setSourceFilename(MODX_BASE_PATH . $input);
    foreach ($params as $key => $value) {
        $phpThumb->setParameter($key, $value);
    }
    if ($phpThumb->GenerateThumbnail()) {
        $phpThumb->RenderToFile($outputFilename);
    } else {
        $modx->logEvent(0, 3, implode('<br/>', $phpThumb->debugmessages), 'phpthumb');
    }
}
return $fname_preffix . rawurlencode($fname);
Example #7
0
 /**
  * Function to create Thumbnail images
  *
  * @param object $model
  * @param string $source Source file name (without path)
  * @param string $target Target file name (without path)
  * @param string $fieldName Path to source and destination (no trailing DS)
  * @param array $params
  * @return void
  * @access protected
  */
 function _createThumbnail(&$model, $source, $target, $fieldName, $params = array())
 {
     $params = array_merge(array('thumbnailQuality' => $this->__fields[$model->alias][$fieldName]['thumbnailQuality'], 'zoomCrop' => false), $params);
     // Import phpThumb class
     App::import('Vendor', 'phpthumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     // Configuring thumbnail settings
     $phpThumb = new phpthumb();
     $phpThumb->setSourceFilename($source);
     $w = isset($params['width']);
     $h = isset($params['height']);
     if ($w && $h) {
         $phpThumb->w = $params['width'];
         $phpThumb->h = $params['height'];
     } elseif ($w && !$h) {
         $phpThumb->w = $params['width'];
     } elseif ($h && !$w) {
         $phpThumb->h = $params['height'];
     } else {
         trigger_error(__d('meio_upload', 'Width and Height of thumbs not specified.', true), E_USER_WARNING);
         return;
     }
     $phpThumb->setParameter('zc', $params['zoomCrop']);
     $phpThumb->q = $params['thumbnailQuality'];
     list(, $phpThumb->config_output_format) = explode('.', $source, 2);
     $phpThumb->config_prefer_imagemagick = $this->__fields[$model->alias][$fieldName]['useImageMagick'];
     $phpThumb->config_imagemagick_path = $this->__fields[$model->alias][$fieldName]['imageMagickPath'];
     // Setting whether to die upon error
     $phpThumb->config_error_die_on_error = true;
     // Creating thumbnail
     if ($phpThumb->GenerateThumbnail()) {
         if (!$phpThumb->RenderToFile($target)) {
             trigger_error(sprintf(__d('meio_upload', 'Could not render image to: %s', true), $target), E_USER_WARNING);
         }
     }
 }
Example #8
0
if (get_magic_quotes_gpc()) {
    $RequestVarsToStripSlashes = array('src', 'wmf', 'file', 'err', 'goto', 'down');
    foreach ($RequestVarsToStripSlashes as $key) {
        if (isset($_GET[$key])) {
            $_GET[$key] = stripslashes($_GET[$key]);
        }
    }
}
// instantiate a new phpthumb() object
ob_start();
if (!(include_once dirname(__FILE__) . '/phpthumb.class.php')) {
    ob_end_flush();
    die('failed to include_once("' . realpath(dirname(__FILE__) . '/phpthumb.class.php') . '")');
}
ob_end_clean();
$phpthumb = new phpthumb();
if (@$_GET['src'] && isset($_GET['md5s']) && empty($_GET['md5s'])) {
    if (eregi('^(f|ht)tp[s]?://', $_GET['src'])) {
        if ($fp_source = @fopen($_GET['src'], 'rb')) {
            $filedata = '';
            while (true) {
                $buffer = fread($fp_source, 16384);
                if (strlen($buffer) == 0) {
                    break;
                }
                $filedata .= $buffer;
            }
            fclose($fp_source);
            $md5s = md5($filedata);
        }
    } else {
 /**
  * Function to create Thumbnail images
  *
  * @param object $model Reference to model
  * @param string $source File name (without path)
  * @param string $target File name (without path)
  * @param string $fieldName
  * @param array $params
  * @return void
  * @access protected
  */
 function _createThumbnail(&$model, $source, $target, $fieldName, $params = array())
 {
     $params = array_merge(array('thumbWidth' => 150, 'thumbHeight' => 225, 'maxDimension' => '', 'thumbnailQuality' => $this->__fields[$model->alias][$fieldName]['thumbnailQuality'], 'zoomCrop' => false), $params);
     // Import phpThumb class
     $test = App::import('Vendor', 'phpthumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     // Configuring thumbnail settings
     $phpThumb = new phpthumb();
     $phpThumb->setSourceFilename($source);
     $phpThumb->config_disable_debug = !Configure::read('debug');
     if ($params['maxDimension'] == 'w') {
         $phpThumb->w = $params['thumbWidth'];
     } else {
         if ($params['maxDimension'] == 'h') {
             $phpThumb->h = $params['thumbHeight'];
         } else {
             $phpThumb->w = $params['thumbWidth'];
             $phpThumb->h = $params['thumbHeight'];
         }
     }
     $phpThumb->setParameter('zc', $this->__fields[$model->alias][$fieldName]['zoomCrop']);
     if (isset($params['zoomCrop'])) {
         $phpThumb->setParameter('zc', $params['zoomCrop']);
     }
     if (isset($params['watermark'])) {
         $phpThumb->fltr = array("wmi|" . IMAGES . $params['watermark'] . "|BR|50|5");
     }
     $phpThumb->q = $params['thumbnailQuality'];
     $imageArray = explode(".", $source);
     $phpThumb->config_output_format = $imageArray[1];
     unset($imageArray);
     $phpThumb->config_prefer_imagemagick = $this->__fields[$model->alias][$fieldName]['useImageMagick'];
     $phpThumb->config_imagemagick_path = $this->__fields[$model->alias][$fieldName]['imageMagickPath'];
     // Setting whether to die upon error
     $phpThumb->config_error_die_on_error = true;
     // Creating thumbnail
     if ($phpThumb->GenerateThumbnail()) {
         if (!$phpThumb->RenderToFile($target)) {
             $this->_addError('Could not render image to: ' . $target);
         }
     }
 }
Example #10
0
 public static function small($file)
 {
     require_once dirname(__FILE__) . '/../phpthumb/phpthumb.class.php';
     $basefile = new File($file);
     $basepath = File::a2r($file);
     $webimg = dirname($basepath) . "/" . $basefile->name . "_small." . $basefile->extension;
     list($x, $y) = getimagesize($file);
     if ($x <= 1200 && $y <= 1200) {
         return $file;
     }
     $path = File::r2a($webimg, Settings::$thumbs_dir);
     /// Create smaller image
     if (!file_exists($path) || filectime($file) > filectime($path)) {
         if (!file_exists(dirname($path))) {
             @mkdir(dirname($path), 0755, true);
         }
         $thumb = new phpthumb();
         $thumb->config_imagemagick_path = Settings::$imagemagick_path;
         $thumb->setSourceData(file_get_contents($file));
         $thumb->CalculateThumbnailDimensions();
         $thumb->w = 1200;
         $thumb->h = 1200;
         $thumb->q = Settings::$quality_small;
         if (File::Type($file) == 'Image' && Provider::get_orientation_degrees($file) != 0) {
             $thumb->SourceImageToGD();
             //$thumb->ra = Provider::get_orientation_degrees($file);
             $thumb->Rotate();
         }
         $thumb->GenerateThumbnail();
         $thumb->RenderToFile($path);
     }
     return $path;
 }
Example #11
0
 /**
  * Function to create Thumbnail images
  *
  * @param object $model Reference to model
  * @param string $source File name (without path)
  * @param string $target File name (without path)
  * @param string $fieldName
  * @param array $params
  * @return void
  * @access protected
  */
 function _createThumbnail(&$model, $source, $target, $fieldName, $params = array())
 {
     # zuha added to have a setting for whether to resize or crop
     $zoomCrop = defined('__GALLERY_RESIZE_OR_CROP') && __GALLERY_RESIZE_OR_CROP == 'crop' ? true : false;
     $params = array_merge(array('thumbWidth' => 150, 'thumbHeight' => 225, 'maxDimension' => '', 'thumbnailQuality' => $this->__fields[$model->alias][$fieldName]['thumbnailQuality'], 'zoomCrop' => $zoomCrop), $params);
     // Import phpThumb class
     //App::import('Vendor', 'Galleries.phpThumb', array('file' => 'phpThumb'.DS.'phpthumb.class.php'));
     require_once APP . 'Plugin' . DS . 'Galleries' . DS . 'vendors' . DS . 'phpThumb' . DS . 'phpthumb.class.php';
     // @todo import
     // Configuring thumbnail settings
     $phpThumb = new phpthumb();
     $phpThumb->setSourceFilename($source);
     if ($params['maxDimension'] == 'w') {
         $phpThumb->w = $params['thumbWidth'];
     } else {
         if ($params['maxDimension'] == 'h') {
             $phpThumb->h = $params['thumbHeight'];
         } else {
             $phpThumb->w = $params['thumbWidth'];
             $phpThumb->h = $params['thumbHeight'];
         }
     }
     $phpThumb->setParameter('zc', $this->__fields[$model->alias][$fieldName]['zoomCrop']);
     if (isset($params['zoomCrop'])) {
         $phpThumb->setParameter('zc', $params['zoomCrop']);
     }
     $phpThumb->q = $params['thumbnailQuality'];
     $imageArray = explode(".", $source);
     $phpThumb->config_output_format = $imageArray[1];
     unset($imageArray);
     $phpThumb->config_prefer_imagemagick = $this->__fields[$model->alias][$fieldName]['useImageMagick'];
     $phpThumb->config_imagemagick_path = $this->__fields[$model->alias][$fieldName]['imageMagickPath'];
     // Setting whether to die upon error
     $phpThumb->config_error_die_on_error = true;
     // Creating thumbnail
     if ($phpThumb->GenerateThumbnail()) {
         if (!$phpThumb->RenderToFile($target)) {
             $this->_addError('Could not render image to: ' . $target);
         }
     }
 }
Example #12
0
 /**
  * 
  * @param string $message
  * @param string $file
  * @param string $line
  * @return bool
  */
 function DebugMessage($message, $file = '', $line = '')
 {
     if (class_exists('\\mnCMS\\Service\\LogService')) {
         \mnCMS\Service\LogService::debug($message . ' file:' . $file . ' line:' . $line);
     }
     return parent::DebugMessage($message, $file, $line);
 }
 public function ImageBorder(&$gdimg, $border_width, $radius_x, $radius_y, $hexcolor_border)
 {
     $border_width = $border_width ? $border_width : 1;
     $radius_x = $radius_x ? $radius_x : 0;
     $radius_y = $radius_y ? $radius_y : 0;
     $output_width = imagesx($gdimg);
     $output_height = imagesy($gdimg);
     list($new_width, $new_height) = phpthumb_functions::ProportionalResize($output_width, $output_height, $output_width - max($border_width * 2, $radius_x), $output_height - max($border_width * 2, $radius_y));
     $offset_x = $radius_x ? $output_width - $new_width - $radius_x : 0;
     if ($gd_border_canvas = phpthumb_functions::ImageCreateFunction($output_width, $output_height)) {
         imagesavealpha($gd_border_canvas, true);
         imagealphablending($gd_border_canvas, false);
         $color_background = phpthumb_functions::ImageColorAllocateAlphaSafe($gd_border_canvas, 255, 255, 255, 127);
         imagefilledrectangle($gd_border_canvas, 0, 0, $output_width, $output_height, $color_background);
         $color_border = phpthumb_functions::ImageHexColorAllocate($gd_border_canvas, phpthumb_functions::IsHexColor($hexcolor_border) ? $hexcolor_border : '000000');
         for ($i = 0; $i < $border_width; $i++) {
             imageline($gd_border_canvas, floor($offset_x / 2) + $radius_x, $i, $output_width - $radius_x - ceil($offset_x / 2), $i, $color_border);
             // top
             imageline($gd_border_canvas, floor($offset_x / 2) + $radius_x, $output_height - 1 - $i, $output_width - $radius_x - ceil($offset_x / 2), $output_height - 1 - $i, $color_border);
             // bottom
             imageline($gd_border_canvas, floor($offset_x / 2) + $i, $radius_y, floor($offset_x / 2) + $i, $output_height - $radius_y, $color_border);
             // left
             imageline($gd_border_canvas, $output_width - 1 - $i - ceil($offset_x / 2), $radius_y, $output_width - 1 - $i - ceil($offset_x / 2), $output_height - $radius_y, $color_border);
             // right
         }
         if ($radius_x && $radius_y) {
             // PHP bug: imagearc() with thicknesses > 1 give bad/undesirable/unpredicatable results
             // Solution: Draw multiple 1px arcs side-by-side.
             // Problem: parallel arcs give strange/ugly antialiasing problems
             // Solution: draw non-parallel arcs, from one side of the line thickness at the start angle
             //   to the opposite edge of the line thickness at the terminating angle
             for ($thickness_offset = 0; $thickness_offset < $border_width; $thickness_offset++) {
                 imagearc($gd_border_canvas, floor($offset_x / 2) + 1 + $radius_x, $thickness_offset - 1 + $radius_y, $radius_x * 2, $radius_y * 2, 180, 270, $color_border);
                 // top-left
                 imagearc($gd_border_canvas, $output_width - $radius_x - 1 - ceil($offset_x / 2), $thickness_offset - 1 + $radius_y, $radius_x * 2, $radius_y * 2, 270, 360, $color_border);
                 // top-right
                 imagearc($gd_border_canvas, $output_width - $radius_x - 1 - ceil($offset_x / 2), $output_height - $thickness_offset - $radius_y, $radius_x * 2, $radius_y * 2, 0, 90, $color_border);
                 // bottom-right
                 imagearc($gd_border_canvas, floor($offset_x / 2) + 1 + $radius_x, $output_height - $thickness_offset - $radius_y, $radius_x * 2, $radius_y * 2, 90, 180, $color_border);
                 // bottom-left
             }
             if ($border_width > 1) {
                 for ($thickness_offset = 0; $thickness_offset < $border_width; $thickness_offset++) {
                     imagearc($gd_border_canvas, floor($offset_x / 2) + $thickness_offset + $radius_x, $radius_y, $radius_x * 2, $radius_y * 2, 180, 270, $color_border);
                     // top-left
                     imagearc($gd_border_canvas, $output_width - $thickness_offset - $radius_x - 1 - ceil($offset_x / 2), $radius_y, $radius_x * 2, $radius_y * 2, 270, 360, $color_border);
                     // top-right
                     imagearc($gd_border_canvas, $output_width - $thickness_offset - $radius_x - 1 - ceil($offset_x / 2), $output_height - $radius_y, $radius_x * 2, $radius_y * 2, 0, 90, $color_border);
                     // bottom-right
                     imagearc($gd_border_canvas, floor($offset_x / 2) + $thickness_offset + $radius_x, $output_height - $radius_y, $radius_x * 2, $radius_y * 2, 90, 180, $color_border);
                     // bottom-left
                 }
             }
         }
         $this->phpThumbObject->ImageResizeFunction($gd_border_canvas, $gdimg, floor(($output_width - $new_width) / 2), round(($output_height - $new_height) / 2), 0, 0, $new_width, $new_height, $output_width, $output_height);
         imagedestroy($gdimg);
         $gdimg = phpthumb_functions::ImageCreateFunction($output_width, $output_height);
         imagesavealpha($gdimg, true);
         imagealphablending($gdimg, false);
         $gdimg_color_background = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg, 255, 255, 255, 127);
         imagefilledrectangle($gdimg, 0, 0, $output_width, $output_height, $gdimg_color_background);
         imagecopy($gdimg, $gd_border_canvas, 0, 0, 0, 0, $output_width, $output_height);
         imagedestroy($gd_border_canvas);
         return true;
     } else {
         $this->DebugMessage('FAILED: $gd_border_canvas = phpthumb_functions::ImageCreateFunction(' . $output_width . ', ' . $output_height . ')', __FILE__, __LINE__);
     }
     return false;
 }
Example #14
0
 /**
  * Create a thumbnail, and cache.
  *
  * @return mixed Cached filename returned if thumbnailing was successful. False on error.
  */
 public function createThumb($src, $dest)
 {
     App::import('Vendor', 'phpthumb', array('file' => 'phpThumb' . DS . 'phpthumb.class.php'));
     if (!class_exists('phpthumb')) {
         trigger_error(__('phpThumb must be installed in the vendors directory: APP/vendors/phpThumb', true), E_USER_ERROR);
     }
     $phpThumb = new phpthumb();
     $phpThumb->setParameter('src', $src);
     foreach ($this->options as $k => $v) {
         if ($k == 'fltr') {
             // Setup the Filtering as string options.
             foreach ($v as $vk => &$vv) {
                 $vv = $vk . '|' . $vv;
             }
             $phpThumb->setParameter($k, $v);
         } else {
             // All non-filter options
             $phpThumb->setParameter($k, $v);
         }
     }
     @ini_set('max_execution_time', 0);
     if ($phpThumb->GenerateThumbnail()) {
         $phpThumb->RenderToFile('img' . DS . $dest);
         return $dest;
     }
     $this->_error = preg_replace('/[^A-Za-z0-9\\/: .]/', '', $phpThumb->fatalerror);
     $this->_error = preg_replace('/phpThumb v[0-9\\.\\-]+/', '', $this->_error);
     return false;
 }
Example #15
0
 * @version  SVN: $Id:\$
 * @link     http://www.mediboard.org
 */
include_once 'lib/phpThumb/phpThumb.config.php';
CAppUI::requireLibraryFile("phpThumb/phpthumb.class");
$file_id = CValue::get("file_id");
$index = CValue::get("index");
$file = new CFile();
$file->load($file_id);
// Si le pdf a été supprimé ou vidé car on ferme la popup sans enregistrer
// le document, alors on ne génère pas la vignette
if (!$file->_id || !file_exists($file->_file_path) || file_get_contents($file->_file_path) == "") {
    return;
}
// Traitement de la vignette
$thumbs = new phpthumb();
// Il faut inclure manuellement la configuration dans l'objet phpThumbs
if (!empty($PHPTHUMB_CONFIG)) {
    foreach ($PHPTHUMB_CONFIG as $key => $value) {
        $keyname = 'config_' . $key;
        $thumbs->setParameter($keyname, $value);
    }
}
$thumbs->setSourceFilename($file->_file_path);
$vignette = null;
$thumbs->sfn = $index;
$thumbs->w = 138;
$thumbs->f = "png";
$thumbs->GenerateThumbnail();
$vignette = base64_encode($thumbs->IMresizedData);
echo json_encode($vignette);
 * @license 	GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
 * @author Agel_Nash <*****@*****.**>
 */
if (!defined('MODX_BASE_PATH')) {
    die('What are you doing? Get out of here!');
}
//[[phpthumb? &input=`[+tvimagename+]` &options=`w_255,h=200`]]
if ($input == '' || !file_exists($_SERVER['DOCUMENT_ROOT'] . "/" . $input)) {
    return 'assets/snippets/phpthumb/noimage.png';
} else {
    $replace = array("," => "&", "_" => "=");
    $options = strtr($options, $replace);
    $opt = $options;
    $path_parts = pathinfo($input);
    require_once MODX_BASE_PATH . "/assets/snippets/phpthumb/phpthumb.class.php";
    $phpThumb = new phpthumb();
    $phpThumb->setSourceFilename($input);
    $options = explode("&", $options);
    $allow = array('f' => 'jpg', 'q' => '96');
    $need = array_keys($allow);
    foreach ($options as $value) {
        $thumb = explode("=", $value);
        if (in_array($thumb[0], $need)) {
            $opt .= "&" . $thumb[0] . "=" . $thumb[1];
            unset($allow[$thumb[0]]);
        }
        $phpThumb->setParameter($thumb[0], $thumb[1]);
        $op[$thumb[0]] = $thumb[1];
    }
    foreach ($allow as $key => $value) {
        $opt .= "&" . $key . "=" . $value;
Example #17
0
 function generateThumbnail($saveAs, $options)
 {
     $destination = WWW_ROOT . $options['directory'] . DS . basename($saveAs);
     $ext = substr(basename($saveAs), strrpos(basename($saveAs), '.') + 1);
     if ($ext == '.jpg' || $ext == '.jpeg') {
         $format = 'jpeg';
     } elseif ($ext == 'png') {
         $format = 'png';
     } elseif ($ext == 'gif') {
         $format = 'gif';
     } else {
         $format = 'jpeg';
     }
     $phpThumb = new phpthumb();
     $phpThumb->setSourceFilename($saveAs);
     $phpThumb->setCacheDirectory(CACHE);
     $phpThumb->setParameter('w', $options['width']);
     if (!empty($option['height'])) {
         $phpThumb->setParameter('h', $options['height']);
     }
     $phpThumb->setParameter('f', $format);
     if (!empty($options['phpThumb'])) {
         foreach ($options['phpThumb'] as $name => $value) {
             if (!empty($value)) {
                 $phpThumb->setParameter($name, $value);
             }
         }
     }
     if ($phpThumb->generateThumbnail()) {
         if ($phpThumb->RenderToFile($destination)) {
             chmod($destination, 0644);
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Example #18
0
 /**
  * Secure PHP Thumb resizing
  */
 public function thumb($img, $properties)
 {
     $file = $img;
     $ext = end(explode('.', $img));
     $kx = '';
     foreach ($properties as $k => $v) {
         $kx .= $k . $v;
     }
     $dir = PUBLIC_DIR . "images/thumbs/";
     $thumb = $dir . hash_hmac('ripemd160', $img . $kx, 'sThumbz1') . '.' . $ext;
     if (!$properties['q']) {
         $properties['q'] = 100;
     }
     if (file_exists($file) && !file_exists($thumb)) {
         if (!is_dir($dir)) {
             mkdir($dir, 0755, true);
         }
         $phpThumb = new phpthumb();
         $PHPTHUMB_CONFIG = array('document_root' => ROOT_DIR, 'cache_directory' => ROOT_DIR . '../application/plugins/phpThumb/cache/', 'imagemagick_path' => 'C:/Program Files (x86)/ImageMagick-6.7.7-Q16/convert.exe', 'disable_debug' => false);
         foreach ($PHPTHUMB_CONFIG as $key => $value) {
             $keyname = 'config_' . $key;
             $phpThumb->setParameter($keyname, $value);
         }
         $phpThumb->setSourceFilename(ROOT_DIR . $file);
         foreach ($properties as $k => $v) {
             $phpThumb->setParameter($k, $v);
         }
         if ($gt = $phpThumb->GenerateThumbnail()) {
             if ($rt = $phpThumb->RenderToFile(ROOT_DIR . $thumb)) {
                 return $thumb;
             } else {
                 return $img;
             }
         } else {
             return $img;
         }
     } elseif (file_exists($thumb)) {
         /*
          * Thumb was already made!
          */
         return $thumb;
     } else {
         /*
          * Return the original input as no file was found in the ul folder
          */
         return $img;
     }
 }
 function ImageCreateFunction($x_size, $y_size)
 {
     $ImageCreateFunction = 'ImageCreate';
     if (phpthumb_functions::gd_version() >= 2.0) {
         $ImageCreateFunction = 'ImageCreateTrueColor';
     }
     if (!function_exists($ImageCreateFunction)) {
         return phpthumb::ErrorImage($ImageCreateFunction . '() does not exist - no GD support?');
     }
     if ($x_size <= 0 || $y_size <= 0) {
         return phpthumb::ErrorImage('Invalid image dimensions: ' . $ImageCreateFunction . '(' . $x_size . ', ' . $y_size . ')');
     }
     return $ImageCreateFunction(round($x_size), round($y_size));
 }
 function gd_info()
 {
     if (function_exists('gd_info')) {
         // built into PHP v4.3.0+ (with bundled GD2 library)
         return gd_info();
     }
     static $gd_info = array();
     if (empty($gd_info)) {
         // based on code by johnschaefer at gmx dot de
         // from PHP help on gd_info()
         $gd_info = array('GD Version' => '', 'FreeType Support' => false, 'FreeType Linkage' => '', 'T1Lib Support' => false, 'GIF Read Support' => false, 'GIF Create Support' => false, 'JPG Support' => false, 'PNG Support' => false, 'WBMP Support' => false, 'XBM Support' => false);
         $phpinfo_array = phpthumb_functions::phpinfo_array();
         foreach ($phpinfo_array as $line) {
             $line = trim(strip_tags($line));
             foreach ($gd_info as $key => $value) {
                 //if (strpos($line, $key) !== false) {
                 if (strpos($line, $key) === 0) {
                     $newvalue = trim(str_replace($key, '', $line));
                     $gd_info[$key] = $newvalue;
                 }
             }
         }
         if (empty($gd_info['GD Version'])) {
             // probable cause: "phpinfo() disabled for security reasons"
             if (function_exists('ImageTypes')) {
                 $imagetypes = ImageTypes();
                 if ($imagetypes & IMG_PNG) {
                     $gd_info['PNG Support'] = true;
                 }
                 if ($imagetypes & IMG_GIF) {
                     $gd_info['GIF Create Support'] = true;
                 }
                 if ($imagetypes & IMG_JPG) {
                     $gd_info['JPG Support'] = true;
                 }
                 if ($imagetypes & IMG_WBMP) {
                     $gd_info['WBMP Support'] = true;
                 }
             }
             // to determine capability of GIF creation, try to use ImageCreateFromGIF on a 1px GIF
             if (function_exists('ImageCreateFromGIF')) {
                 if ($tempfilename = phpthumb::phpthumb_tempnam()) {
                     if ($fp_tempfile = @fopen($tempfilename, 'wb')) {
                         fwrite($fp_tempfile, base64_decode('R0lGODlhAQABAIAAAH//AP///ywAAAAAAQABAAACAUQAOw=='));
                         // very simple 1px GIF file base64-encoded as string
                         fclose($fp_tempfile);
                         // if we can convert the GIF file to a GD image then GIF create support must be enabled, otherwise it's not
                         $gd_info['GIF Read Support'] = (bool) @ImageCreateFromGIF($tempfilename);
                     }
                     unlink($tempfilename);
                 }
             }
             if (function_exists('ImageCreateTrueColor') && @ImageCreateTrueColor(1, 1)) {
                 $gd_info['GD Version'] = '2.0.1 or higher (assumed)';
             } elseif (function_exists('ImageCreate') && @ImageCreate(1, 1)) {
                 $gd_info['GD Version'] = '1.6.0 or higher (assumed)';
             }
         }
     }
     return $gd_info;
 }
 /**
  * Ajoute un champ
  *
  * @param string  $field      nom du champ
  * @param string  $value      [optional]
  * @param array   $options    [optional]
  * @param boolean $htmlescape [optional]
  *
  * @return void
  */
 function addProperty($field, $value = null, $options = array(), $htmlescape = true)
 {
     if ($htmlescape) {
         $value = CMbString::htmlSpecialChars($value);
     }
     $sec = explode(' - ', $field, 3);
     switch (count($sec)) {
         case 3:
             $section = $sec[0];
             $item = $sec[1];
             $sub_item = $sec[2];
             break;
         case 2:
             $section = $sec[0];
             $item = $sec[1];
             $sub_item = '';
             break;
         default:
             trigger_error("Error while exploding the string", E_USER_ERROR);
             return;
     }
     if (!array_key_exists($section, $this->sections)) {
         $this->sections[$section] = array();
     }
     if ($sub_item != '' && !array_key_exists($item, $this->sections[$section])) {
         $this->sections[$section][$item] = array();
     }
     if ($sub_item == '') {
         $this->sections[$section][$field] = array("view" => CMbString::htmlEntities($item), "field" => $field, "value" => $value, "fieldHTML" => CMbString::htmlEntities("[{$field}]", ENT_QUOTES), "valueHTML" => $value, "shortview" => $section . " - " . $item, "options" => $options);
     } else {
         $this->sections[$section][$item][$sub_item] = array("view" => CMbString::htmlEntities($sub_item), "field" => $field, "value" => $value, "fieldHTML" => CMbString::htmlEntities("[{$field}]", ENT_QUOTES), "valueHTML" => $value, "shortview" => $section . " - " . $item . " - " . $sub_item, "options" => $options);
     }
     // Barcode
     if (isset($options["barcode"])) {
         if ($sub_item) {
             $_field =& $this->sections[$section][$item][$sub_item];
         } else {
             $_field =& $this->sections[$section][$field];
         }
         if ($this->valueMode) {
             $src = $this->getBarcodeDataUri($_field['value'], $options["barcode"]);
         } else {
             $src = $_field['fieldHTML'];
         }
         $_field["field"] = "";
         if ($options["barcode"]["title"]) {
             $_field["field"] .= $options["barcode"]["title"] . "<br />";
         }
         $_field["field"] .= "<img alt=\"{$field}\" src=\"{$src}\" ";
         foreach ($options["barcode"] as $name => $attribute) {
             $_field["field"] .= " {$name}=\"{$attribute}\"";
         }
         $_field["field"] .= "/>";
     }
     // Custom data
     if (isset($options["data"])) {
         $_field =& $this->sections[$section][$item][$sub_item];
         $data = $options["data"];
         $view = $_field['field'];
         $_field["field"] = "[<span data-data=\"{$data}\">{$view}</span>]";
     }
     // Image (from a CFile object)
     if (isset($options["image"])) {
         $_field =& $this->sections[$section][$field];
         $data = "";
         if ($this->valueMode) {
             $file = new CFile();
             $file->load($_field['value']);
             if ($file->_id) {
                 // Resize the image
                 CAppUI::requireLibraryFile("phpThumb/phpthumb.class");
                 include_once "lib/phpThumb/phpThumb.config.php";
                 $thumbs = new phpthumb();
                 $thumbs->setSourceFilename($file->_file_path);
                 $thumbs->w = 640;
                 $thumbs->f = "png";
                 $thumbs->GenerateThumbnail();
                 $data = "data:" . $file->file_type . ";base64," . urlencode(base64_encode($thumbs->IMresizedData));
             }
         }
         $src = $this->valueMode ? $data : $_field['fieldHTML'];
         $_field["field"] = "<img src=\"" . $src . "\" />";
     }
 }
Example #22
0
    if ($basePath != '/') {
        $src = str_replace(basename($basePath), '', $src);
        $src = ltrim($src, '/');
        $src = $basePath . $src;
    }
}
if (!isset($config['modphpthumb'])) {
    // make sure we get a few relevant system settings
    $config['modphpthumb'] = array();
    $config['modphpthumb']['config_allow_src_above_docroot'] = (bool) $modx->getOption('phpthumb_allow_src_above_docroot', null, false);
    $config['modphpthumb']['zc'] = $modx->getOption('phpthumb_zoomcrop', null, 0);
    $config['modphpthumb']['far'] = $modx->getOption('phpthumb_far', null, 'C');
    $config['modphpthumb']['config_ttf_directory'] = MODX_CORE_PATH . 'model/phpthumb/fonts/';
    $config['modphpthumb']['config_document_root'] = $modx->getOption('phpthumb_document_root', null, '');
}
$phpThumb = new phpthumb();
// unfortunately we have to create a new object for each image!
foreach ($config['modphpthumb'] as $param => $value) {
    // add MODX system settings
    $phpThumb->{$param} = $value;
}
foreach ($ptOptions as $param => $value) {
    // add options passed to the snippet
    $phpThumb->setParameter($param, $value);
}
// try to avert problems when $_SERVER['DOCUMENT_ROOT'] is different than MODX_BASE_PATH
if (!$phpThumb->config_document_root) {
    $phpThumb->config_document_root = MODX_BASE_PATH;
    // default if nothing set from system settings
}
$phpThumb->config_cache_directory = $assetsPath . 'cache/';