Exemplo n.º 1
0
<?php

/**
 * PhpThumb Library Example File
 *
 * This file contains example usage for the PHP Thumb Library
 *
 * PHP Version 5 with GD 2.0+
 * PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
 * Copyright (c) 2009, Ian Selby/Gen X Design
 *
 * Author(s): Ian Selby <*****@*****.**>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../vendor/autoload.php';
$thumb = new PHPThumb\GD(__DIR__ . '/../tests/resources/test.jpg');
$thumb->cropFromCenter(200, 100);
$thumb->show();
Exemplo n.º 2
0
<?php

/**
 * PhpThumb Library Example File
 *
 * This file contains example usage for the PHP Thumb Library
 *
 * PHP Version 5 with GD 2.0+
 * PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
 * Copyright (c) 2009, Ian Selby/Gen X Design
 *
 * Author(s): Ian Selby <*****@*****.**>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../../vendor/autoload.php';
$thumb = new PHPThumb\GD(__DIR__ . '/../../public/imgs/test.jpg', array(), array(new PHPThumb\Plugins\Reflection(40, 40, 80, true, '#a4a4a4')));
$thumb->adaptiveResize(250, 250);
$thumb->show();
Exemplo n.º 3
0
<?php

/**
 * PhpThumb Library Example File
 *
 * This file contains example usage for the PHP Thumb Library
 *
 * PHP Version 5 with GD 2.0+
 * PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
 * Copyright (c) 2009, Ian Selby/Gen X Design
 *
 * Author(s): Ian Selby <*****@*****.**>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../vendor/autoload.php';
$thumb = new PHPThumb\GD('http://phpthumb.gxdlabs.com/wp-content/themes/phpthumb/images/header_bg.png');
$thumb->resize(200, 200);
$thumb->show();
Exemplo n.º 4
0
 /**
  * Create thumbnails from uploaded image
  *
  * @return void
  */
 private function _create_thumbs()
 {
     // Thumbnails
     foreach ($this->_thumbnails as $thumbnail) {
         // Create dir for thumbnail
         $this->_fs->mkdir($this->_config['dir'] . $thumbnail['dir']);
         // Previous saved image
         $thumb = new PHPThumb\GD($this->_config['dir'] . $this->_newfilename);
         // Set jpeg quality for thumbnail
         $thumb->setOptions(array('jpegQuality' => $thumbnail['jpeg_quality']));
         // If fixed size
         if ($thumbnail['adaptive']) {
             $thumb->adaptiveResize($thumbnail['max_width'], $thumbnail['max_height']);
         } else {
             $thumb->resize($thumbnail['max_width'], $thumbnail['max_height']);
         }
         // Save the image file to directory
         $thumb->save($this->_config['dir'] . $thumbnail['dir'] . DS . $this->_newfilename);
     }
 }
Exemplo n.º 5
0
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../../vendor/autoload.php';
$fileData = file_get_contents('test.jpg');
//此处由于构造方法只认绝对路径或者url路径,所以会抛出错误
$thumb = new PHPThumb\GD($fileData);
$thumb->crop(100, 100, 300, 200);
// $imageAsString will contain the image data suitable for saving in a database.
$imageAsString = $thumb->getImageAsString();
?>
<h2>Here's the Image Data:</h2>
<strong>Note:</strong> This should be a bunch of gibberish<br />
<div style="overflow: auto; width: 500px; height: 400px; border: 1px solid #e4e4e4; padding: 5px;"><?php 
echo htmlentities($imageAsString);
?>
</div>

<h2>Here's that data as an image:</h2>
<img src="data:image/png;base64,<?php 
echo base64_encode($imageAsString);
?>
Exemplo n.º 6
0
<?php

/**
 * PhpThumb Library Example File
 *
 * This file contains example usage for the PHP Thumb Library
 *
 * PHP Version 5 with GD 2.0+
 * PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
 * Copyright (c) 2009, Ian Selby/Gen X Design
 *
 * Author(s): Ian Selby <*****@*****.**>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../tests/bootstrap.php';
$thumb = new PHPThumb\GD(__DIR__ . '/../tests/resources/test.jpg');
$thumb->resize(100, 100);
$thumb->show();
Exemplo n.º 7
0
 /**
  * Generate the thumbnail
  *
  * @access	public
  * @return	void
  **/
 public function index()
 {
     //	Check the request headers; avoid hitting the disk at all if possible. If the Etag
     //	matches then send a Not-Modified header and terminate execution.
     if ($this->_serve_not_modified($this->_cache_file)) {
         return;
     }
     // --------------------------------------------------------------------------
     //	The browser does not have a local cache (or it's out of date) check the
     //	cache to see if this image has been processed already; serve it up if
     //	it has.
     if (file_exists(DEPLOY_CACHE_DIR . $this->_cache_file)) {
         $this->_serve_from_cache($this->_cache_file);
     } else {
         //	Cache object does not exist, fetch the original, process it and save a
         //	version in the cache bucket.
         //	Which original are we using?
         switch ($this->_sex) {
             case 'female':
             case 'woman':
             case 'f':
             case 'w':
             case '2':
                 $_src = $this->_woman;
                 break;
                 // --------------------------------------------------------------------------
             // --------------------------------------------------------------------------
             case 'male':
             case 'man':
             case 'm':
             case '1':
                 $_src = $this->_man;
                 break;
                 // --------------------------------------------------------------------------
                 //	Fallback to a default avatar
                 //	TODO: Make this avatar gender neutral
             // --------------------------------------------------------------------------
             //	Fallback to a default avatar
             //	TODO: Make this avatar gender neutral
             default:
                 $_src = $this->_man;
                 break;
         }
         if (file_exists($_src)) {
             //	Object exists, time for manipulation fun times :>
             //	Set some PHPThumb options
             $_options['resizeUp'] = TRUE;
             // --------------------------------------------------------------------------
             //	Perform the resize
             $PHPThumb = new PHPThumb\GD($_src, $_options);
             $PHPThumb->adaptiveResize($this->_width, $this->_height);
             // --------------------------------------------------------------------------
             //	Set the appropriate cache headers
             $this->_set_cache_headers(time(), $this->_cache_file, FALSE);
             // --------------------------------------------------------------------------
             //	Output the newly rendered file to the browser
             $PHPThumb->show();
             // --------------------------------------------------------------------------
             //	Save local version
             $PHPThumb->save(DEPLOY_CACHE_DIR . $this->_cache_file);
         } else {
             //	This object does not exist.
             log_message('error', 'CDN: Blank Avatar: File not found; ' . $_src);
             return $this->_bad_src($this->_width, $this->_height);
         }
     }
 }
Exemplo n.º 8
0
<?php

/**
 * PhpThumb Library Example File
 *
 * This file contains example usage for the PHP Thumb Library
 *
 * PHP Version 5 with GD 2.0+
 * PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
 * Copyright (c) 2009, Ian Selby/Gen X Design
 *
 * Author(s): Ian Selby <*****@*****.**>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../vendor/autoload.php';
$thumb = new PHPThumb\GD(__DIR__ . '/../tests/resources/test.jpg');
$thumb->rotateImage('CW');
$thumb->show();
// or:
// $thumb->rotate('CCW');
Exemplo n.º 9
0
<?php

/**
 * PhpThumb Library Example File
 *
 * This file contains example usage for the PHP Thumb Library
 *
 * PHP Version 5 with GD 2.0+
 * PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
 * Copyright (c) 2009, Ian Selby/Gen X Design
 *
 * Author(s): Ian Selby <*****@*****.**>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../../vendor/autoload.php';
$thumb = new PHPThumb\GD(__DIR__ . '/../../public/imgs/test.jpg');
$thumb->adaptiveResize(175, 175);
$thumb->show();
Exemplo n.º 10
0
<?php

/**
 * PhpThumb Library Example File
 *
 * This file contains example usage for the PHP Thumb Library
 *
 * PHP Version 5 with GD 2.0+
 * PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
 * Copyright (c) 2009, Ian Selby/Gen X Design
 *
 * Author(s): Ian Selby <*****@*****.**>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../vendor/autoload.php';
$thumb = new PHPThumb\GD(__DIR__ . '/../tests/resources/test.jpg');
$thumb->rotateImageNDegrees(180);
$thumb->show();
Exemplo n.º 11
0
 public static function GetThumbResource($oAccount, $rResource, $sFileName, $bShow = true)
 {
     $sMd5Hash = md5(rand(1000, 9999));
     $oApiFileCache = \CApi::GetSystemManager('filecache');
     $oApiFileCache->putFile($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, $rResource, '_' . $sFileName);
     if ($oApiFileCache->isFileExists($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, '_' . $sFileName)) {
         try {
             $oThumb = new \PHPThumb\GD($oApiFileCache->generateFullFilePath($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, '_' . $sFileName));
             if ($bShow) {
                 $oThumb->adaptiveResize(120, 100)->show();
             } else {
                 return $oThumb->adaptiveResize(120, 100)->getImageAsString();
             }
         } catch (\Exception $oE) {
         }
     }
     $oApiFileCache->clear($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, '_' . $sFileName);
 }
Exemplo n.º 12
0
 private function _resize_animated($usefile, $PHPThumb_method)
 {
     $_hash = md5(microtime(TRUE) . uniqid()) . uniqid();
     $_frames = array();
     $_cachefiles = array();
     $_durations = array();
     $_gfe = new GifFrameExtractor\GifFrameExtractor();
     $_gc = new GifCreator\GifCreator();
     // --------------------------------------------------------------------------
     //	Extract all the frames, resize them and save to the cache
     $_gfe->extract($usefile);
     $_i = 0;
     foreach ($_gfe->getFrames() as $frame) {
         //	Define the filename
         $_filename = $_hash . '-' . $_i . '.gif';
         $_temp_filename = $_hash . '-' . $_i . '-original.gif';
         $_i++;
         //	Set these for recompiling
         $_frames[] = $this->_cachedir . $_filename;
         $_cachefiles[] = $this->_cachedir . $_temp_filename;
         $_durations[] = $frame['duration'];
         // --------------------------------------------------------------------------
         //	Set some PHPThumb options
         $_options = array();
         $_options['resizeUp'] = TRUE;
         // --------------------------------------------------------------------------
         //	Perform the resize; first save the original frame to disk
         imagegif($frame['image'], $this->_cachedir . $_temp_filename);
         $PHPThumb = new PHPThumb\GD($this->_cachedir . $_temp_filename, $_options);
         $PHPThumb->{$PHPThumb_method}($this->_width, $this->_height);
         // --------------------------------------------------------------------------
         //	Save cache version
         $PHPThumb->save($this->_cachedir . $_filename, strtoupper(substr($this->_extension, 1)));
     }
     //	Recompile the resized images back into an animated gif and save to the cache
     //	TODO: We assume the gif loops infinitely but we should really check.
     //	Issue made on the libraries gitHub asking for this feature.
     //	View here: https://github.com/Sybio/GifFrameExtractor/issues/3
     $_gc->create($_frames, $_durations, 0);
     $_data = $_gc->getGif();
     // --------------------------------------------------------------------------
     //	Output to browser
     header('Content-Type: image/gif', TRUE);
     echo $_data;
     // --------------------------------------------------------------------------
     //	Save to cache
     $this->load->helper('file');
     write_file($this->_cachedir . $this->_cache_file, $_data);
     // --------------------------------------------------------------------------
     //	Remove cache frames
     foreach ($_frames as $frame) {
         @unlink($frame);
     }
     foreach ($_cachefiles as $frame) {
         @unlink($frame);
     }
     // --------------------------------------------------------------------------
     //	Kill script, th, th, that's all folks.
     //	Stop the output class from hijacking our headers and
     //	setting an incorrect Content-Type
     exit(0);
 }
Exemplo n.º 13
0
<?php

/**
 * PhpThumb Library Example File
 *
 * This file contains example usage for the PHP Thumb Library
 *
 * PHP Version 5 with GD 2.0+
 * PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
 * Copyright (c) 2009, Ian Selby/Gen X Design
 *
 * Author(s): Ian Selby <*****@*****.**>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Oleg Sherbakov <*****@*****.**>
 * @copyright Copyright (c) 2016
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../vendor/autoload.php';
$thumb = new PHPThumb\GD(__DIR__ . '/../tests/resources/test.jpg', array(), array(new PHPThumb\Plugins\Trim(array(255, 255, 255), 'TBLR')));
$thumb->show();
Exemplo n.º 14
0
<?php

require_once '../PHPThumb/PHPThumb.php';
require_once '../PHPThumb/GD.php';
// get the thumbnail from the URL
$src = strip_tags(htmlspecialchars($_GET['thumb']));
error_log('thumb : ' . $src);
@mkdir(dirname($src), 0777, true);
$thumb = new PHPThumb\GD('../' . $src);
$thumb->adaptiveResize(175, 175);
$thumb->save($src);
$thumb->show();
Exemplo n.º 15
0
<?php

/**
 * PhpThumb Library Example File
 *
 * This file contains example usage for the PHP Thumb Library
 *
 * PHP Version 5 with GD 2.0+
 * PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
 * Copyright (c) 2009, Ian Selby/Gen X Design
 *
 * Author(s): Ian Selby <*****@*****.**>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../tests/bootstrap.php';
$thumb = new PHPThumb\GD(__DIR__ . '/../tests/resources/test.jpg');
$thumb->adaptiveResize(300, 300);
$thumb->save('test.png', 'png');
Exemplo n.º 16
0
 /**
  * @param bool $bDownload
  * @param bool $bThumbnail = false
  *
  * @return bool
  */
 private function rawSmart($bDownload, $bThumbnail = false)
 {
     $sRawKey = (string) $this->GetActionParam('RawKey', '');
     $aValues = $this->getDecodedRawKeyValue($sRawKey);
     $sFolder = isset($aValues['Folder']) ? $aValues['Folder'] : '';
     $iUid = isset($aValues['Uid']) ? (int) $aValues['Uid'] : 0;
     $sMimeIndex = isset($aValues['MimeIndex']) ? (string) $aValues['MimeIndex'] : '';
     $sContentTypeIn = isset($aValues['MimeType']) ? (string) $aValues['MimeType'] : '';
     $sFileNameIn = isset($aValues['FileName']) ? (string) $aValues['FileName'] : '';
     $sFileHashIn = isset($aValues['FileHash']) ? (string) $aValues['FileHash'] : '';
     if (!empty($sFileHashIn)) {
         $this->verifyCacheByKey($sRawKey);
         $oAccount = $this->getAccountFromToken();
         $sContentTypeOut = empty($sContentTypeIn) ? \MailSo\Base\Utils::MimeContentType($sFileNameIn) : $sContentTypeIn;
         $sFileNameOut = $this->MainClearFileName($sFileNameIn, $sContentTypeIn, $sMimeIndex);
         $rResource = $this->FilesProvider()->GetFile($oAccount, $sFileHashIn);
         if (\is_resource($rResource)) {
             $sFileNameOut = \MailSo\Base\Utils::ConvertEncoding($sFileNameOut, \MailSo\Base\Enumerations\Charset::UTF_8, \MailSo\Base\Enumerations\Charset::CP858);
             \header('Content-Type: ' . $sContentTypeOut);
             \header('Content-Disposition: attachment; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true);
             \header('Accept-Ranges: none', true);
             \header('Content-Transfer-Encoding: binary');
             \MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource);
             return true;
         }
         return false;
     } else {
         if (!empty($sFolder) && 0 < $iUid) {
             $this->verifyCacheByKey($sRawKey);
         }
     }
     $oAccount = $this->initMailClientConnection();
     $self = $this;
     return $this->MailClient()->MessageMimeStream(function ($rResource, $sContentType, $sFileName, $sMimeIndex = '') use($self, $oAccount, $sRawKey, $sContentTypeIn, $sFileNameIn, $bDownload, $bThumbnail) {
         if ($oAccount && \is_resource($rResource)) {
             $sContentTypeOut = $sContentTypeIn;
             if (empty($sContentTypeOut)) {
                 $sContentTypeOut = $sContentType;
                 if (empty($sContentTypeOut)) {
                     $sContentTypeOut = empty($sFileName) ? 'text/plain' : \MailSo\Base\Utils::MimeContentType($sFileName);
                 }
             }
             $sFileNameOut = $sFileNameIn;
             if (empty($sFileNameOut)) {
                 $sFileNameOut = $sFileName;
             }
             $sFileNameOut = $self->MainClearFileName($sFileNameOut, $sContentTypeOut, $sMimeIndex);
             $self->cacheByKey($sRawKey);
             $bDone = false;
             if ($bThumbnail && !$bDownload) {
                 $sFileName = '';
                 $rTempResource = \MailSo\Base\StreamWrappers\TempFile::CreateStream(\MailSo\Base\Utils::Md5Rand($sFileNameOut), $sFileName);
                 if (@\is_resource($rTempResource)) {
                     $bDone = true;
                     \MailSo\Base\Utils::MultipleStreamWriter($rResource, array($rTempResource));
                     @\fclose($rTempResource);
                     try {
                         $oThumb = new \PHPThumb\GD($sFileName);
                         if ($oThumb) {
                             $oThumb->adaptiveResize(60, 60)->show();
                         }
                     } catch (\Exception $oException) {
                         $self->Logger()->WriteExceptionShort($oException);
                     }
                 }
             }
             if (!$bDone) {
                 \header('Content-Type: ' . $sContentTypeOut);
                 \header('Content-Disposition: ' . ($bDownload ? 'attachment' : 'inline') . '; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true);
                 \header('Accept-Ranges: none', true);
                 \header('Content-Transfer-Encoding: binary');
                 \MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource);
             }
         }
     }, $sFolder, $iUid, true, $sMimeIndex);
 }
Exemplo n.º 17
0
 public function thumbResource($oAccount, $rResource, $sFileName)
 {
     $sMd5Hash = md5(rand(1000, 9999));
     $this->ApiFileCache()->putFile($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, $rResource, '_' . $sFileName);
     if ($this->ApiFileCache()->isFileExists($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, '_' . $sFileName)) {
         try {
             $oThumb = new \PHPThumb\GD($this->ApiFileCache()->generateFullFilePath($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, '_' . $sFileName));
             $oThumb->adaptiveResize(120, 100)->show();
         } catch (\Exception $oE) {
         }
     }
     $this->ApiFileCache()->clear($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, '_' . $sFileName);
 }
Exemplo n.º 18
0
<?php

/**
 * PhpThumb Library Example File
 *
 * This file contains example usage for the PHP Thumb Library
 *
 * PHP Version 5 with GD 2.0+
 * PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
 * Copyright (c) 2009, Ian Selby/Gen X Design
 *
 * Author(s): Ian Selby <*****@*****.**>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../vendor/autoload.php';
$thumb = new PHPThumb\GD(__DIR__ . '/../tests/resources/test.jpg');
$thumb->resizePercent(50);
$thumb->show();
Exemplo n.º 19
0
<?php

/**
 * PhpThumb Library Example File
 *
 * This file contains example usage for the PHP Thumb Library
 *
 * PHP Version 5 with GD 2.0+
 * PhpThumb : PHP Thumb Library <http://phpthumb.gxdlabs.com>
 * Copyright (c) 2009, Ian Selby/Gen X Design
 *
 * Author(s): Ian Selby <*****@*****.**>
 *
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @subpackage Examples
 * @filesource
 */
require_once '../../vendor/autoload.php';
$thumb = new PHPThumb\GD(__DIR__ . '/../../public/imgs/test.jpg');
$thumb->crop(100, 100, 300, 200);
$thumb->show();
Exemplo n.º 20
0
 private function thumbs_save($path)
 {
     $path_parts = pathinfo($path);
     $filename = $path_parts['basename'];
     $this->json['group'] = Arr::get($_POST, 'group');
     $config = Config::get($this->json['group'], true);
     $dir = UPLOAD_DIR . $config['dir'] . DS;
     if (isset($config['thumbnails'])) {
         foreach ($config['thumbnails'] as $thumbnail) {
             // Cropped saved image
             $thumb = new PHPThumb\GD($dir . $filename);
             // If fixed size
             if ($thumbnail['adaptive']) {
                 $thumb->adaptiveResize($thumbnail['max_width'], $thumbnail['max_height']);
             } else {
                 $thumb->resize($thumbnail['max_width'], $thumbnail['max_height']);
             }
             // Save the image file to directory
             $thumb->save($dir . $thumbnail['dir'] . DS . $filename);
         }
     }
 }