public function attach_file($file, $campo) { global $database; // Determine the target_path $this->temp_path = $file['tmp_name']; switch ($file['type']) { case "image/gif": $this->foto = $campo . "-" . $this->id . ".gif"; break; case "image/png": $this->foto = $campo . "-" . $this->id . ".png"; break; default: $this->foto = $campo . "-" . $this->id . ".jpg"; } $target_path = $this->upload_dir . "/" . $this->foto; // Attempt to move the file if (move_uploaded_file($this->temp_path, $target_path)) { // Success $tn_image = new Thumbnail($this->upload_dir . "/" . $this->foto, 640, 0, 0); $tn_image->save($this->upload_dir . "/" . $this->foto); // Save a corresponding entry to the database $sql = "UPDATE " . self::$table_name . " SET " . $campo . " = '" . $this->foto . "' WHERE id = '" . $this->id . "'"; if ($database->query($sql)) { // We are done with temp_path, the file isn't there anymore unset($this->temp_path); return true; } } }
/** * Creates and saves a thumbnail picture. */ public function createThumbnail($thumbnailWidth = ATTACHMENT_THUMBNAIL_WIDTH, $thumbnailHeight = ATTACHMENT_THUMBNAIL_HEIGHT, $addSourceInfo = ATTACHMENT_THUMBNAIL_ADD_SOURCE_INFO, $useEmbedded = ATTACHMENT_THUMBNAIL_USE_EMBEDDED) { // make thumbnail $sourceFile = WCF_DIR . 'attachments/attachment-' . $this->attachmentID; $targetFile = WCF_DIR . 'attachments/thumbnail-' . $this->attachmentID; $thumbnail = new Thumbnail($sourceFile, $thumbnailWidth, $thumbnailHeight, $addSourceInfo, $this->attachmentName, $useEmbedded); // get thumbnail try { if ($thumbnailData = $thumbnail->makeThumbnail()) { // save thumbnail $file = new File($targetFile); $file->write($thumbnailData); unset($thumbnailData); $file->close(); // update database entry $thumbnailSize = intval(filesize($targetFile)); list($thumbnailWidth, $thumbnailHeight, ) = @getImagesize($targetFile); $sql = "UPDATE\twcf" . WCF_N . "_attachment\n\t\t\t\t\tSET \tthumbnailType = '" . escapeString($thumbnail->getMimeType()) . "',\n\t\t\t\t\t\tthumbnailSize = " . $thumbnailSize . ",\n\t\t\t\t\t\tthumbnailWidth = " . $thumbnailWidth . ",\n\t\t\t\t\t\tthumbnailHeight = " . $thumbnailHeight . "\n\t\t\t\t\tWHERE \tattachmentID = " . $this->attachmentID; WCF::getDB()->registerShutdownUpdate($sql); // update data $this->data['thumbnailType'] = $thumbnail->getMimeType(); $this->data['thumbnailSize'] = $thumbnailSize; } } catch (Exception $e) { } }
function handleDirFiles($dir_name, $save_dir) { list($directories, $files) = File_Find::maptree($dir_name); $new_dir = $save_dir . basename($dir_name); if (!file_exists($new_dir)) { mkdir($new_dir, 0777); } foreach ($files as $image_file) { if (ereg("(.*)jpg\$", $image_file)) { $new_filename = $new_dir . "/" . basename($image_file, ".jpg") . "_resize.jpg"; echo $new_filename . "\n"; $tn_image = new Thumbnail($image_file, 340); $tn_image->save($new_filename); $Canvas =& Image_Canvas::factory(isset($_GET['canvas']) ? $_GET['canvas'] : 'jpg', array('width' => 340, 'height' => 340)); $Canvas->image(array('x' => 340, 'y' => 340, 'filename' => $new_filename, 'alignment' => array('horizontal' => 'right', 'vertical' => 'bottom'))); $Canvas->setFont(array('name' => 'Courier New', 'size' => 16, 'color' => '#FF66FF')); //#FF0033 $Canvas->addText(array('x' => 165, 'y' => 200, 'text' => 'arzen1013', 'alignment' => array('horizontal' => 'center', 'vertical' => 'bottom'))); $Canvas->setFont(array('name' => 'Courier New', 'size' => 10, 'color' => '#000000')); //#FF0033 $Canvas->addText(array('x' => 165, 'y' => 320, 'text' => 'http://shop33691629.taobao.com/', 'alignment' => array('horizontal' => 'center', 'vertical' => 'bottom'))); $Canvas->save(array('filename' => $new_filename)); } } }
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}'/>"; }
public function index() { $u = new SwfUpload(); $t = new Thumbnail(); $u->files = $_FILES; //设置file数组。(只能单张) //请记住先检测,再上传 $r = $u->check(); if ($r === true && ($r = $u->upload())) { // echo_log($r); if (!isset($r['error'])) { // 生成200的缩略图 $t->setSrcImg($r['savePath']); $height = $t->getImgHeight(); $width = $t->getImgWidth(); if ($this->savePicture($r['saveName'], $r['title'], $width, $height)) { // 生成小的缩略图 $t->setDstImg($r['savePath'] . '_' . THUMBNAIL_WIDTH_SMALL); $t->createImg(THUMBNAIL_WIDTH_SMALL); // 生成打的缩略图 $t->setSrcImg($r['savePath']); $t->setDstImg($r['savePath'] . '_' . THUMBNAIL_WIDTH_LARGE); $t->createImg(THUMBNAIL_WIDTH_LARGE); $rt = array('thumbUrl' => $r['saveName'], 'title' => $r['title'], 'width' => $width, 'height' => $height); json_success($rt); } else { json_failure('图片信息入库异常'); } } else { json_failure($r['error']); } } else { json_failure($r['error']); } }
/** * Generates a thumbnail for the specified image path and size, then serves * it to the browser. The next time the same thumbnail is rendered its URL * will point to the generated image instead of this action. * @see Thumbnail * @param string $path the thumbnail path * @param int $size the thumbnail size * @throws PageNotFoundException if the image could not be generated */ public function actionGenerate($path, $size) { $thumbnail = new Thumbnail($path, $size); $thumbnail->generate(); $path = $thumbnail->getPath(); if ($path === false) { throw new PageNotFoundException(); } header('Content-Type: ' . CFileHelper::getMimeType($path)); readfile($path); exit; }
/** * 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); }
public static function getAvatar(\User $user, $res) { global $wgDefaultAvatar, $wgDefaultAvatarRes; $path = $wgDefaultAvatar; // If user exists if ($user && $user->getId()) { global $wgUploadDirectory, $wgUploadPath; $avatarPath = "/avatars/{$user->getId()}/{$res}.png"; // Check if requested avatar thumbnail exists if (file_exists($wgUploadDirectory . $avatarPath)) { $path = $wgUploadPath . $avatarPath; } else { if ($res !== 'original') { // Dynamically generate upon request $originalAvatarPath = "/avatars/{$user->getId()}/original.png"; if (file_exists($wgUploadDirectory . $originalAvatarPath)) { $image = Thumbnail::open($wgUploadDirectory . $originalAvatarPath); $image->createThumbnail($res, $wgUploadDirectory . $avatarPath); $image->cleanup(); $path = $wgUploadPath . $avatarPath; } } } } return $path; }
private function processUpload() { $request = $this->getRequest(); $dataurl = $request->getVal('avatar'); if (!$dataurl || parse_url($dataurl, PHP_URL_SCHEME) !== 'data') { $this->displayMessage($this->msg('avatar-notuploaded')); return false; } $img = Thumbnail::open($dataurl); global $wgMaxAvatarResolution; switch ($img->type) { case IMAGETYPE_GIF: case IMAGETYPE_PNG: case IMAGETYPE_JPEG: break; default: $this->displayMessage($this->msg('avatar-invalid')); return false; } // Must be square if ($img->width !== $img->height) { $this->displayMessage($this->msg('avatar-notsquare')); return false; } // Check if image is too small if ($img->width < 32 || $img->height < 32) { $this->displayMessage($this->msg('avatar-toosmall')); return false; } // Check if image is too big if ($img->width > $wgMaxAvatarResolution || $img->height > $wgMaxAvatarResolution) { $this->displayMessage($this->msg('avatar-toolarge')); return false; } $user = $this->getUser(); Avatars::deleteAvatar($user); // Avatar directories global $wgAvatarUploadDirectory; $uploadDir = $wgAvatarUploadDirectory . '/' . $this->getUser()->getId() . '/'; @mkdir($uploadDir, 0777, true); // We do this to convert format to png $img->createThumbnail($wgMaxAvatarResolution, $uploadDir . 'original.png'); // We only create thumbnail with default resolution here. Others are generated on demand global $wgDefaultAvatarRes; $img->createThumbnail($wgDefaultAvatarRes, $uploadDir . $wgDefaultAvatarRes . '.png'); $img->cleanup(); $this->displayMessage($this->msg('avatar-saved')); global $wgAvatarLogInRC; $logEntry = new \ManualLogEntry('avatar', 'upload'); $logEntry->setPerformer($this->getUser()); $logEntry->setTarget($this->getUser()->getUserPage()); $logId = $logEntry->insert(); $logEntry->publish($logId, $wgAvatarLogInRC ? 'rcandudp' : 'udp'); return true; }
public function toHtml() { $classes = "entry " . ($this->isFolder ? "folder " : "file ") . $this->type; $imgClass = ""; $img = $this->type; $smallImg = $this->h5ai->icon($this->type); $bigImg = $this->h5ai->icon($this->type, true); $hint = ""; if ($this->isFolder && $this->type !== "folder-parent") { $code = $this->h5ai->getHttpCode($this->absHref); $classes .= " checkedHttpCode"; if ($code !== "h5ai") { if ($code === 200) { $img = "folder-page"; $smallImg = $this->h5ai->icon("folder-page"); $bigImg = $this->h5ai->icon("folder-page", true); } else { $classes .= " error"; $hint = "<span class='hint'> " . $code . " </span>"; } } } if ($this->h5ai->showThumbs() && in_array($this->type, $this->h5ai->getThumbTypes())) { $imgClass = " class='thumb' "; $thumbnail = new Thumbnail($this->h5ai, $this->absHref, "square", 16, 16); $thumbnail->create(); $smallImg = file_exists($thumbnail->getPath()) ? $thumbnail->getHref() : $thumbnail->getLiveHref(); $thumbnail = new Thumbnail($this->h5ai, $this->absHref, "rational", 96, 46); $thumbnail->create(); $bigImg = file_exists($thumbnail->getPath()) ? $thumbnail->getHref() : $thumbnail->getLiveHref(); } $html = "\t<li class='" . $classes . "'>\n"; $html .= "\t\t<a href='" . $this->absHref . "'>\n"; $html .= "\t\t\t<span class='icon small'><img " . $imgClass . " src='" . $smallImg . "' alt='" . $img . "' /></span>\n"; $html .= "\t\t\t<span class='icon big'><img " . $imgClass . " src='" . $bigImg . "' alt='" . $img . "' /></span>\n"; $html .= "\t\t\t<span class='label'>" . $this->label . $hint . "</span>\n"; $html .= "\t\t\t<span class='date' data-time='" . $this->date . "000'></span>\n"; $html .= "\t\t\t<span class='size' data-bytes='" . $this->size . "'>" . $this->size . "</span>\n"; $html .= "\t\t</a>\n"; $html .= "\t</li>\n"; return $html; }
protected function processImgUpload() { //if no errors are found $thumbnail = new Thumbnail(); if (is_uploaded_file($this->Filetemp_name)) { //$this->Filename = rename($this->Filename,$upload_time."_".$this->Filename); $tmploc = move_uploaded_file($this->Filetemp_name, $this->Temp_dir . $this->Filename); if ($tmploc) { $thumbnail->createThumbnail($this->Temp_dir . $this->Filename, $this->Thumb_dir . $this->Filename, self::MAX_THUMB_WIDTH, self::MAX_THUMB_HEIGHT); $thumbnail->createThumbnail($this->Temp_dir . $this->Filename, $this->Upload_dir . $this->Filename, self::MAX_IMG_WIDTH, self::MAX_IMG_HEIGHT); list($new_width, $new_height) = getimagesize($this->Upload_dir . $this->Filename); $this->Newfilename = $this->getFilename($this->Filename, "."); $this->File_ext = $this->get_file_extension($this->Filename); $this->Filesize = $this->Filesize; $this->Width = $new_width; $this->Height = $new_height; $this->Filetype; } $this->deleteFile($this->Temp_dir . $this->Filename); } }
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); } }
/** * Get the thumbnail relative URI. * * @param Thumbnail $thumb * * @return mixed */ private function getThumbnailUri(Thumbnail $thumb) { if ($thumb->getFileName() == null) { return false; } $app = $this->getContainer(); return $app['url_generator']->generate('thumb', ['width' => $thumb->getWidth(), 'height' => $thumb->getHeight(), 'action' => $thumb->getScale(), 'file' => $thumb->getFileName()]); }
/** * Perfoms manipulation * * @param string $from * @param string $to * @param string $options * @return void */ public function manipulate($from, $to, $options) { if (false === class_exists('Thumbnail')) { throw new Yag_Manipulator_Adapter_Exception('Class Thumbnail could not be loaded'); } if (!isset($options['geometry'])) { throw new Yag_Manipulator_Adapter_Exception('Thumbnail requires the \'geometry\' option to be set'); } $matches = array(); preg_match('/(c)?([0-9]+)x([0-9]+)/', $options['geometry'], $matches); $crop = empty($matches[1]) ? false : true; $width = $matches[2]; $height = $matches[3]; if (empty($matches[2])) { throw new Yag_Manipulator_Adapter_Exception('Invalid geometry pattern \'' . $options['geometry'] . '\''); } if (empty($matches[3])) { throw new Yag_Manipulator_Adapter_Exception('Invalid geometry pattern \'' . $options['geometry'] . '\''); } $thumbnail = new Thumbnail($from); // TODO: Fix error handling around this... $quality = 80; if (false == $crop) { $thumbnail->resize($width, $height); $quality = 100; } else { if ($width == $height) { // Well works for now... the crop for ImageTransform is a bit better // but who cares? $thumbnail->cropFromCenter($width); } else { $thumbnail->crop(0, 0, $width, $height); } } $thumbnail->save($to, $quality); }
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'); } } } } }
public function getThumbnail($path) { $this->ensureAccess($path); $image = new Thumbnail($path); $this->setImageHeaders($path, $image->getType()); $image->downscale(); $image->render(); }
function testExistingFileHasContent() { $thumbnail = new Thumbnail(array('id' => 'example/Untitled-17.jpg')); $raw_data = $thumbnail->getData(); $this->assertTrue(strlen($raw_data) > 0); }
function parseTargeImage_old($picPath) { $getrxpath = dirname(__FILE__) . '/../..'; $ret_graph_small_picture_path = '/data/attachment/forum/mobcentSmallPreview/'; $ret_graph_big_picture_path = '/data/attachment/forum/mobcentBigPreview/'; $ret_graph_xgsize_picture_path = '/data/attachment/forum/xgsize/'; $origan_path = $getrxpath . "/../../data/attachment/forum/" . $picPath['attachment']; $origan = explode('/', $picPath['attachment']); $origan_path_date = $getrxpath . "/../../data/attachment/forum/" . date('Ym/d', $picPath['dateline']) . '/' . $origan[count($origan) - 1]; $path = pathinfo($picPath['attachment']); $fileName = $path['filename'] . '.' . $path['extension']; $Url = explode('/', $this->getRootFolder(SELF_FOLDER)); unset($Url[count($Url) - 1]); $Url = implode('/', $Url); $ret_suffix_xgsize = $ret_graph_xgsize_picture_path . $picPath['attachment']; $ret_suffix = $ret_graph_small_picture_path . $picPath['attachment']; $ret_path_attachmentImg = $getrxpath . '/..' . $ret_suffix; $ret_path_small = $getrxpath . '/..' . $ret_graph_small_picture_path . $path['dirname'] . '/'; $ret_path_big = $getrxpath . '/..' . $ret_graph_big_picture_path . $path['dirname'] . '/'; $size = 160; $sizeBig = 480; if (file_exists($origan_path)) { if (file_exists($ret_path_attachmentImg)) { $pic_path = '/mobcent' . $ret_suffix_xgsize; } else { $pic = new Thumbnail($origan_path); if ($pic->zoomcutPic($origan_path, $ret_path_small, $fileName, $size) && $pic->zoomcutPic($origan_path, $ret_path_big, $fileName, $sizeBig)) { $pic_path = '/mobcent' . $ret_graph_xgsize_picture_path . $path['dirname'] . '/' . $path['filename'] . '.' . $path['extension']; } } } else { if (file_exists($origan_path_date)) { $path = pathinfo(date('Ym/d', $picPath['dateline']) . '/' . $origan[count($origan) - 1]); $fileName = $path['filename'] . '.' . $path['extension']; $Url = explode('/', $this->getRootFolder(SELF_FOLDER)); unset($Url[count($Url) - 1]); $Url = implode('/', $Url); $ret_suffix_xgsize = $ret_graph_xgsize_picture_path . '/' . date('Ym/d', $picPath['dateline']) . '/' . $origan[count($origan) - 1]; $ret_suffix = $ret_graph_small_picture_path . '/' . date('Ym/d', $picPath['dateline']) . '/' . $origan[count($origan) - 1]; $ret_path_attachmentImg = $this->getPath() . '/..' . $ret_suffix; $ret_path_small = $this->getPath() . '/..' . $ret_graph_small_picture_path . $path['dirname'] . '/'; $ret_path_big = $this->getPath() . '/..' . $ret_graph_big_picture_path . $path['dirname'] . '/'; $size = 160; if (file_exists($ret_path_attachmentImg)) { $pic_path = '/mobcent' . $ret_suffix_xgsize; } else { $pic = new Thumbnail($origan_path_date); if ($pic->zoomcutPic($origan_path_date, $ret_path_small, $fileName, $size) && $pic->zoomcutPic($origan_path_date, $ret_path_big, $fileName, $sizeBig)) { $pic_path = '/mobcent' . $ret_graph_xgsize_picture_path . $path['dirname'] . '/' . $path['filename'] . '.' . $path['extension']; } } } } return $pic_path; }
<?php //error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR); error_reporting(0); require './roots.php'; require $root_path . 'include/inc_environment_global.php'; /* CARE2X Integrated Information System for Hospitals and Health Care Organizations and Services Copyright (C) 2002,2003,2004,2005 Elpidio Latorilla & Intellin.org GNU GPL. For details read file "copy_notice.txt". */ if (!extension_loaded('gd')) { dl('php_gd.dll'); } require $root_path . 'classes/thumbnail/thumbnail.class.php'; $myThumb = new Thumbnail(); // Start using a class $myThumb->setMaxSize($mx, $my); // Specify maximum size (width, height) $myThumb->setImgSource($root_path . $imgfile); // Specify original image filename $myThumb->Create(''); // Specify destination image filename or leave empty to output directly
if (!is_file($fullpath)) { js_fail("File {$fullpath} does not exist."); } $imgInfo = @getImageSize($fullpath); //Not an image, bail out. if (!is_array($imgInfo)) { js_fail("File {$fullpath} is not an image."); } if (!isset($_GET['to'])) { $resized = $manager->getResizedName($fullpath, $_GET['width'], $_GET['height']); $_GET['to'] = $manager->getResizedName($image, $_GET['width'], $_GET['height'], FALSE); } else { $resized = Files::makeFile($manager->getImagesDir(), $_GET['to']); } // Check to see if it already exists if (is_file($resized)) { // And is newer if (filemtime($resized) >= filemtime($fullpath)) { js_success($_GET['to']); } } // resize (thumbnailer will do this for us just fine) $thumbnailer = new Thumbnail($_GET['width'], $_GET['height']); $thumbnailer->proportional = FALSE; $thumbnailer->createThumbnail($fullpath, $resized); // did it work? if (is_file($resized)) { js_success($_GET['to']); } else { js_fail("Resize Failed."); }
private function processGetFile($item) { if (count($this->path) == 1) { $mobile = ($this->env->request()->hasParam("m") and strcmp($this->env->request()->param("m"), "1") == 0); if (isset($_SERVER['HTTP_RANGE'])) { $this->env->filesystem()->download($item, $mobile, $_SERVER['HTTP_RANGE']); } else { $this->env->filesystem()->download($item, $mobile); } return; } switch (strtolower($this->path[1])) { case 'thumbnail': if (!$item->isFile()) { throw $this->invalidRequestException(); } if (!in_array(strtolower($item->extension()), array("gif", "png", "jpg", "jpeg"))) { throw $this->invalidRequestException(); } if ($this->env->settings()->setting("enable_thumbnails")) { require_once "include/Thumbnail.class.php"; $maxWidth = 400; $maxHeight = 400; if ($this->env->request()->hasParam("mw") and $this->env->request()->hasParam("mh")) { $maxWidth = intval($this->env->request()->param("mw")); $maxHeight = intval($this->env->request()->param("mh")); } $t = new Thumbnail(); if ($t->generate($item, $maxWidth, $maxHeight)) { die; } } $this->env->filesystem()->view($item); return; case 'view': $this->env->filesystem()->view($item); die; case 'details': $this->response()->success($this->env->filesystem()->details($item)); break; default: throw $this->invalidRequestException(); } }
} //if the image is less than the thumbnail dimensions //send the original image as thumbnail if ($imgInfo[0] <= $IMConfig['thumbnail_width'] && $imgInfo[1] <= $IMConfig['thumbnail_height']) { header('Location: ' . $manager->getFileURL($image)); exit; } //Check for thumbnails $thumbnail = $manager->getThumbName($fullpath); if (is_file($thumbnail)) { //if the thumbnail is newer, send it if (filemtime($thumbnail) >= filemtime($fullpath)) { header('Location: ' . $manager->getThumbURL($image)); exit; } } //creating thumbnails $thumbnailer = new Thumbnail($IMConfig['thumbnail_width'], $IMConfig['thumbnail_height']); $thumbnailer->createThumbnail($fullpath, $thumbnail); //Check for NEW thumbnails if (is_file($thumbnail)) { //send the new thumbnail header('Location: ' . $manager->getThumbURL($image)); exit; } else { //show the default image, otherwise we quit! $default = $manager->getDefaultThumb(); if ($default) { header('Location: ' . $default); } }
function getThumb($text, $size = 70, $reflections = false) { preg_match("/\\<img.+?src=\"(.+?)\".+?\\/>/", $text, $matches); $paths = array(); if (isset($matches[1])) { $image_path = $matches[1]; //joomla 1.5 only $full_url = JURI::base(); //remove any protocol/site info from the image path $parsed_url = parse_url($full_url); $paths[] = $full_url; if (isset($parsed_url['path']) && $parsed_url['path'] != "/") { $paths[] = $parsed_url['path']; } foreach ($paths as $path) { if (strpos($image_path, $path) !== false) { $image_path = substr($image_path, strpos($image_path, $path) + strlen($path)); } } // remove any / that begins the path if (substr($image_path, 0, 1) == '/') { $image_path = substr($image_path, 1); } //if after removing the uri, still has protocol then the image //is remote and we don't support thumbs for external images if (strpos($image_path, 'http://') !== false || strpos($image_path, 'https://') !== false) { return false; } // create a thumb filename $file_div = strrpos($image_path, '.'); $thumb_ext = substr($image_path, $file_div); $thumb_prev = substr($image_path, 0, $file_div); $thumb_path = $thumb_prev . "_thumb" . $thumb_ext; // check to see if this file exists, if so we don't need to create it if (function_exists("gd_info") && !file_exists($thumb_path)) { // file doens't exist, so create it and save it include_once 'thumbnail.inc.php'; $thumb = new Thumbnail($image_path); if ($thumb->error) { if (MICRONEWS) { echo "ROKMININEWS ERROR: " . $thumb->errmsg . ": " . $image_path; } return false; } $thumb->resize($size); if ($reflections) { $thumb->createReflection(30, 30, 60, false); } if (!is_writable(dirname($thumb_path))) { $thumb->destruct(); return false; } $thumb->save($thumb_path); $thumb->destruct(); } return $thumb_path; } else { return false; } }
/** * create Thumbnail * * @param none */ function createThumbnail() { global $leaguemanager; $image = $leaguemanager->getImagePath($this->image); $thumb = $leaguemanager->getThumbnailPath($this->image); $thumbnail = new Thumbnail($image); $thumbnail->resize(60, 60); $thumbnail->save($image); $thumbnail->resize(30, 30); $thumbnail->save($thumb); chmod($image, 0644); chmod($thumb, 0644); }
<?php //Thumbnail sample include 'Thumbnail.class.php'; $thumb = new Thumbnail("source.jpg"); // Contructor and set source image file //$thumb->memory_limit='32M'; //[OPTIONAL] set maximun memory usage, default 32 MB ('32M'). (use '16M' or '32M' for litter images) //$thumb->max_execution_time='30'; //[OPTIONAL] set maximun execution time, default 30 seconds ('30'). (use '60' for big images o slow server) /* $thumb->quality=85; // [OPTIONAL] default 75 , only for JPG format $thumb->output_format='JPG'; // [OPTIONAL] JPG | PNG $thumb->jpeg_progressive=0; // [OPTIONAL] set progressive JPEG : 0 = no , 1 = yes $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
if (!file_exists($URL_long)) { mkdir($carpeta, 0755); if (isset($_FILES["imagen"])) { $temp = $_FILES["imagen"]["tmp_name"]; $thumb = new Thumbnail($temp); if ($thumb->error) { echo $thumb->error; } else { $thumb->resize(200, 150); $thumb->save_jpg($URL_long, $nombre_archivo); } } } else { if (isset($_FILES["imagen"])) { $temp = $_FILES["imagen"]["tmp_name"]; $thumb = new Thumbnail($temp); if ($thumb->error) { echo $thumb->error; } else { $thumb->resize(200, 150); $thumb->save_jpg($URL_long, $nombre_archivo); } } } //FIN cambio de imagen ************ echo 1; return; } } } else { header("Location: ../plantillas/errorPrivilegios.html");
<?php include dirname(__FILE__) . "/init.php"; require_once ISC_BASE_PATH . "/includes/classes/class.thumbnail.php"; $width = (int) $_GET['width']; $height = (int) $_GET['height']; $path = $_GET['path']; $imagename = ISC_BASE_PATH . "/" . $path; $thumb = new Thumbnail($imagename); //$thumb->resizeToWidth(240); $thumb->resize($width, $height); $thumb->show(); $thumb->destruct();
} $hrefs = preg_split("/;/", $hrefs); $codes = getHttpCodes($h5ai, $hrefs); echo count($codes) === 0 ? "{}" : json_encode($codes); } else { if ($action === "thumb") { fail(0, "thumbs are disabled", !$options["showThumbs"]); list($srcAbsHref, $width, $height, $mode) = checkKeys(array("href", "width", "height", "mode")); require_once "inc/Thumbnail.php"; require_once "inc/Image.php"; $srcAbsPath = $h5ai->getDocRoot() . rawurldecode($srcAbsHref); if (!Thumbnail::isUsable()) { Image::showImage($srcAbsPath); exit; } $thumbnail = new Thumbnail($h5ai, $srcAbsHref, $mode, $width, $height); $thumbnail->create(1); if (file_exists($thumbnail->getPath())) { Image::showImage($thumbnail->getPath()); } else { $image = new Image(); $image->setSource($srcAbsPath); $image->thumb($mode, $width, $height); $image->showDest(); } } else { if ($action === "tree") { list($href) = checkKeys(array("href")); require_once "inc/Tree.php"; $absHref = trim($href); $absPath = $h5ai->getAbsPath($absHref);
include 'add.html.php'; exit; } /* This class is used to create a thumbnail from the uploaded image. */ require_once INCLUDES_PATH . "Thumbnail.class.php"; /* Generate a unique filename based on the server time and the users ip address. */ $uniqueFilename = md5(time() . $_SERVER['REMOTE_ADDR']); /* Build the artwork and thumb filenames and folder names. */ $artworkFilename = "pic-{$uniqueFilename}.jpg"; $thumbFilename = "thumb-{$artworkFilename}"; $artworkFilePath = ROOT_ARTWORK_PATH . $artworkFilename; $thumbnailFilePath = ROOT_THUMBNAIL_PATH . $thumbFilename; /* Move the uploaded temporary file to the artwork folder. */ move_uploaded_file($tempFilename, $artworkFilePath); /* Instantiate a blank thumbnail and load the artwork image. */ $thumbnail = new Thumbnail(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT); $thumbnail->loadFile($artworkFilePath); /* These properties of the thumbnail are based on the dimentions of the uploaded artwork image. */ $thumbOrientation = $thumbnail->getThumbOrientation(); $thumbOffsetMax = $thumbnail->getThumbOffsetMax(); /* Generate the thumbnail image. */ $thumbnail->buildThumb($thumbnailFilePath); /* Get the values submitted by the form. */ $values = $frmAdd->exportValues(); try { /* Save the properties of the new artwork to the database. */ $sql = "\n INSERT INTO gallery_images\n (title, filename, thumb_orientation, thumb_offset_max, gallery_id)\n VALUES\n (:title, :filename, :thumb_orientation, :thumb_offset_max, :gallery_id)\n "; $stmt = $pdo->prepare($sql); $stmt->bindParam(':title', $values['txtTitle']); $stmt->bindParam(':filename', $artworkFilename); $stmt->bindParam(':thumb_orientation', $thumbOrientation);
<?php //Thumbnail sample include 'Thumbnail.class.php'; $thumb = new Thumbnail("source.jpg"); // Contructor and set source image file $thumb->size_auto(300); // [OPTIONAL] set the biggest width or height for thumbnail $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->txt_watermark = 'Font 1'; // [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 = 1; // [OPTIONAL] set watermark text font: 1,2,3,4,5 $thumb->txt_watermark_Valing = 'TOP'; // [OPTIONAL] set watermark text vertical position, TOP | CENTER | BOTTOM $thumb->txt_watermark_Haling = 'LEFT'; // [OPTIONAL] set watermark text horizonatal position, LEFT | CENTER | RIGHT $thumb->process(); // generate image $thumb->txt_watermark = 'Font 2'; // [OPTIONAL] set watermark text [RECOMENDED ONLY WITH GD 2 ] $thumb->txt_watermark_color = 'FFFFFF'; // [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 = 'TOP';