<?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');
Esempio n. 2
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);
 }
Esempio n. 3
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);
     }
 }
Esempio n. 4
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();
Esempio n. 5
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);
 }
Esempio 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 '../../vendor/autoload.php';
$thumb = new PHPThumb\GD(__DIR__ . '/../../public/imgs/test.jpg');
$thumb->adaptiveResize(175, 175);
$thumb->show();
Esempio n. 7
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);
 }
Esempio n. 8
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);
         }
     }
 }
Esempio n. 9
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);
         }
     }
 }