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