25/05/2009, 05:03
|
| Colaborador | | Fecha de Ingreso: mayo-2009 Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años Puntos: 1517 | |
Respuesta: Reescalar imagen - Guardarla luego Este codigo lo consegui hace un tiempo y siempre me ha funcionado para escalar la imagen Código PHP: <?php /** * A PHP class providing a set of methods for doing basic transformation to an image like resizing, * rotating, flipping and cropping * * You don't need to do any checking on the files you work with - the class takes care of all error * checking and you can find out what went wrong by reading the {@link error} property * * The code is heavily documented so you can easily understand every aspect of it * * See the documentation for more info. * * Read the LICENSE file, provided with the package, to find out how you can use this PHP script. * * If you don't find this file, please write an email to noname at nivelzero dot ro and you will be sent a copy of the license file * * For more resources visit {@link http://stefangabos.blogspot.com} * * @author Stefan Gabos <[email protected]> * @version 1.0.5 (last revision: August 23, 2007) * @copyright (c) 2006 - 2007 Stefan Gabos * @package imageTransform * @example example.php */ error_reporting(E_ALL); class imageTransform { /** * Path and name of image file to transform * * @var string */ var $sourceFile; /** * Path and name of transformed image file * * @var string */ var $targetFile; /** * Available only for the {@link resize} method * * Width, in pixels, to resize the image to * * the property will not be taken into account if is set to -1 * * default is -1 * * @var integer */ var $resizeToWidth; /** * Available only for the {@link resize} method * * Height, in pixels, to resize the image to * * the property will not be taken into account if is set to -1 * * default is -1 * * @var integer */ var $resizeToHeight; /** * Available only for the {@link resize} method * * while resizing, image will keep it's aspect ratio if this property is set to TRUE, and only one of the * {@link resizeToWidth} or {@link resizeToHeight} properties is set. if set to TRUE, and both * {@link resizeToWidth} or {@link resizeToHeight} properties are set, the image will be resized to maximum width/height * so that neither one of them will exceed given width/height while keeping the aspect ratio * * default is TRUE * * @var boolean */ var $maintainAspectRatio; /** * Available only for the {@link resize} method * * image is resized only if image width/height is smaller than the values of * {@link resizeToWidth}/{@link resizeToHeight} properties * * default is TRUE * * @var boolean */ var $resizeIfSmaller; /** * Available only for the {@link resize} method * * image is resized only if image width/height is greater than the values of * {@link resizeToWidth}/{@link resizeToHeight} properties * * default is TRUE * * @var boolean */ var $resizeIfGreater; /** * Available only for the {@link resize} method and only if the {@link targetFile}'s extension is jpg/jpeg * * output quality of image (better quality means bigger file size). * * range is 0 - 100 * * default is 75 * * @var integer */ var $jpegOutputQuality; /** * what rights should the transformed file have * * by default a file created by a script will have the script as owner and you would not be able to edit, modify * or delete the file. better is to leave this setting as it is * * if you know what you're doing, here's is how you calculate the permission levels * * - 400 Owner Read * - 200 Owner Write * - 100 Owner Execute * - 40 Group Read * - 20 Group Write * - 10 Group Execute * - 4 Global Read * - 2 Global Write * - 1 Global Execute * * default is 0755 * * @var integer */ var $chmodValue; /** * Sets weather the target file should have have the same date/time as the source file * * Default is TRUE * * @since 1.0.4 * * @var boolean */ var $preserveSourceFileTime; /** * in case of an error read this property's value to find out what went wrong * * possible error values are: * * - 1: source file could not be found * - 2: source file can not be read * - 3: could not write target file * - 4: unsupported source file * - 5: unsupported target file * - 6: available version of GD does not support target file extension * * default is 0 * * @var integer */ var $error; /** * Constructor of the class. * * @access private */ |