本文整理汇总了PHP中Thumbnail类的典型用法代码示例。如果您正苦于以下问题:PHP Thumbnail类的具体用法?PHP Thumbnail怎么用?PHP Thumbnail使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Thumbnail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attach_file
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;
}
}
}
示例2: createThumbnail
/**
* 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) {
}
}
示例3: handleDirFiles
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));
}
}
}
示例4: thumbnail
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}'/>";
}
示例5: index
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']);
}
}
示例6: actionGenerate
/**
* 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;
}
示例7: imageGenerator
/**
* 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);
}
示例8: getAvatar
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;
}
示例9: processUpload
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;
}
示例10: toHtml
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;
}
示例11: processImgUpload
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);
}
}
示例12: createThumb
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);
}
}
示例13: getThumbnailUri
/**
* 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()]);
}
示例14: manipulate
/**
* 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);
}
示例15: createThumbs
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');
}
}
}
}
}