function thumbnail($filename, $width = 640, $height = 480) { jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); $source = "/media/com_arcnaanimals/{$filename}"; if (!JFile::exists(JPATH_ROOT . $source)) { return false; } $destination = "/media/com_arcnaanimals/thumbs/{$width}_{$height}_{$filename}"; if (!JFile::exists(JPATH_ROOT . $destination)) { if (!JFolder::exists(dirname(JPATH_ROOT . $destination))) { JFolder::create(dirname(JPATH_ROOT . $destination)); } require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/thumbnail/Thumbnail.class.php'; $thumb = new Thumbnail(JPATH_ROOT . $source); // Contructor and set source image file $thumb->size($width, $height); // [OPTIONAL] set the biggest width and height for thumbnail $thumb->process(); // generate image // save the file ob_start(); $thumb->show(); $output = ob_get_contents(); ob_end_clean(); JFile::write(JPATH_ROOT . $destination, $output); } $url = JURI::root(true) . $destination; return "<img src='{$url}' alt='{$filename}'/>"; }
/** * Image generator. * * @param string $imageFile Image name. * @param int $maxSize Max size. * @param string $newFileName New generated file name. * @param int $qualitat Quality. * @param string $waterMark Watermark. * * @return array Image resolution. */ public static function imageGenerator($imageFile, $maxSize, $newFileName, $qualitat, $waterMark = '') { if (!file_exists($imageFile)) { return false; } // Size setter. list($width, $height, $type) = getimagesize($imageFile); $larger = $width > $height ? $width : $height; $smaller = $width > $height ? $height : $width; if ($larger <= $maxSize) { $newLarger = $larger; $newSmaller = $smaller; } else { $multiplication = $maxSize / $larger; $newLarger = $maxSize; $newSmaller = $smaller * $multiplication; } $newWidth = $width > $height ? $newLarger : $newSmaller; $newHeight = $width > $height ? $newSmaller : $newLarger; switch ($type) { case 1: $kep = imagecreatefromgif($imageFile); break; case 2: $kep = imagecreatefromjpeg($imageFile); break; case 3: $kep = imagecreatefrompng($imageFile); break; } $ujkep = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($ujkep, $kep, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); imagejpeg($ujkep, $newFileName, $qualitat); // Contructor and set source image file $thumb = new Thumbnail($newFileName); // [OPTIONAL] set maximun memory usage, default 32 MB ('32M'). (use '16M' or '32M' for litter images) $thumb->memory_limit = '64M'; // [OPTIONAL] set maximun execution time, default 30 seconds ('30'). (use '60' for big images o slow server) $thumb->max_execution_time = 60; if ($waterMark != '') { // [OPTIONAL] set watermark source file, only PNG format [RECOMENDED ONLY WITH GD 2] $thumb->img_watermark = 'static/images/watermak/' . $waterMark; } // [OPTIONAL] set watermark vertical position, TOP | CENTER | BOTTOM $thumb->img_watermark_Valing = 'CENTER'; // [OPTIONAL] set watermark horizonatal position, LEFT | CENTER | RIGHT $thumb->img_watermark_Haling = 'CENTER'; $thumb->process(); $newImage = $thumb->dump(); imagejpeg($newImage, $newFileName, $qualitat); return array($newWidth, $newHeight); }
protected static function createThumb($image, $target, $size, $quality) { $source = self::getRealFilename($image); //ini_set('memory_limit', '128M'); $thumb = new Thumbnail($source); if ($size) { $size_array = explode('x', $size); if (is_numeric($size_array[0])) { $thumb->size_width($size_array[0]); } if (is_numeric($size_array[1])) { $thumb->size_height($size_array[1]); } } if (is_numeric($quality)) { $thumb->quality = $quality; } $thumb->process(); if (!$thumb->save($target)) { throw new Image_Handler_Exception($image, $thumb->error_msg); } }
protected function createThumbs($file, $targets) { global $eshop_picture_config; $dir_photo = KIWI_DIR_PRODUCTS; foreach ($targets as $target) { if (!array_key_exists($target, $eshop_picture_config)) { throw new Exception('Für das Vorschaubild Ziel unbekannt'); } if (is_array($eshop_picture_config[$target])) { $t = new Thumbnail("{$dir_photo}photo/{$file}"); $t->size($eshop_picture_config[$target][0], $eshop_picture_config[$target][1]); $t->quality = 80; $t->output_format = 'JPG'; $this->log("Erstellen einer Miniaturansicht zu das Bild {$file} in das Verzeichnis {$target}"); $t->process(); if (!$this->_simulation) { $status = $t->save("{$dir_photo}{$target}/{$file}"); if (!$status) { throw new Exception('Fehler beim Speichern einer Miniaturansicht des Bildes'); } } } } }
$thumb->allow_enlarge=false; // [OPTIONAL] allow to enlarge the thumbnail //$thumb->CalculateQFactor(10000); // [OPTIONAL] Calculate JPEG quality factor for a specific size in bytes //$thumb->bicubic_resample=false; // [OPTIONAL] set resample algorithm to bicubic */ $thumb->img_watermark = 'watermark.png'; // [OPTIONAL] set watermark source file, only PNG format [RECOMENDED ONLY WITH GD 2 ] /* $thumb->img_watermark_Valing='TOP'; // [OPTIONAL] set watermark vertical position, TOP | CENTER | BOTTON $thumb->img_watermark_Haling='LEFT'; // [OPTIONAL] set watermark horizonatal position, LEFT | CENTER | RIGHT $thumb->txt_watermark='Watermark Text'; // [OPTIONAL] set watermark text [RECOMENDED ONLY WITH GD 2 ] $thumb->txt_watermark_color='FF0000'; // [OPTIONAL] set watermark text color , RGB Hexadecimal[RECOMENDED ONLY WITH GD 2 ] $thumb->txt_watermark_font=5; // [OPTIONAL] set watermark text font: 1,2,3,4,5 $thumb->txt_watermark_Valing='BOTTOM'; // [OPTIONAL] set watermark text vertical position, TOP | CENTER | BOTTOM $thumb->txt_watermark_Haling='RIGHT'; // [OPTIONAL] set watermark text horizonatal position, LEFT | CENTER | RIGHT $thumb->txt_watermark_Hmargin=10; // [OPTIONAL] set watermark text horizonatal margin in pixels $thumb->txt_watermark_Vmargin=10; // [OPTIONAL] set watermark text vertical margin in pixels $thumb->size_width(150); // [OPTIONAL] set width for thumbnail, or $thumb->size_height(113); // [OPTIONAL] set height for thumbnail, or $thumb->size_auto(150); // [OPTIONAL] set the biggest width or height for thumbnail */ $thumb->size(150, 113); // [OPTIONAL] set the biggest width and height for thumbnail $thumb->process(); // generate image $thumb->show(); // show your thumbnail, or //$thumb->save("thumbnail.".$thumb->output_format); // save your thumbnail to file, or //$image = $thumb->dump(); // get the image //echo ($thumb->error_msg); // print Error Mensage
protected function scalePicture($file) { global $eshop_picture_config; $t = new Thumbnail(KIWI_DIR_ACTIONS_PIC . $file); $t->size($eshop_picture_config['action'][0], $eshop_picture_config['action'][1]); $t->quality = 80; $t->output_format = 'JPG'; $t->process(); $status = $t->save(KIWI_DIR_ACTIONS_PIC . $file); if (!$status) { throw new Exception('Chyba při ukládání miniatury obrázku'); } }
protected function createThumbs($file, $targets) { global $eshop_picture_config; $dir_photo = KIWI_DIR_PRODUCTS; foreach ($targets as $target) { if (!array_key_exists($target, $eshop_picture_config)) { throw new Exception('Neznámý cíl pro miniaturu fotografie'); } if (is_array($eshop_picture_config[$target])) { $t = new Thumbnail("{$dir_photo}photo/{$file}"); $t->size($eshop_picture_config[$target][0], $eshop_picture_config[$target][1]); $t->quality = 80; $t->output_format = 'JPG'; $t->process(); $status = $t->save("{$dir_photo}{$target}/{$file}"); if (!$status) { throw new Exception('Chyba při ukládání miniatury obrázku'); } } } }
/** * Watermark Image * * @param string $imageFile Source image file (../files/images/product-1.jpg) * @param string $watermarkImage Watermark Image file (../templates/img/logo.png) * @param string $valign Vertical align (LEFT | CENTER | RIGHT) * @param string $halign Horizontal align (LEFT | CENTER | RIGHT) * * return boolean True if images watermarked, False if not * */ public function WatermarkImage($imageFile, $watermarkImage = "", $valign = "", $halign = "") { global $rootPath; $imageExt = strtoupper(substr($imageFile, strrpos($imageFile, ".") + 1)); // File extension require_once $rootPath . INC_THUMBNAIL . "Thumbnail.class.php"; $thumb = new Thumbnail($imageFile); $thumb->quality = 80; $thumb->output_format = $imageExt; $thumb->img_watermark = $watermarkImage ? $watermarkImage : $rootPath . INC_THUMBNAIL . "logo.png"; $thumb->img_watermark_Valing = $valign ? $valign : "BOTTOM"; $thumb->img_watermark_Haling = $halign ? $halign : "CENTER"; $thumb->process(); if (!$thumb->save($imageFile)) { $this->SetError($thumb->error_msg, __FILE__, __LINE__); return false; } return true; }