<?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');
/** * 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); } }
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); }
<?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();
/** * 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); } } }
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); } } }