示例#1
0
function getImageConverterInstance()
{
    if (!isset($GLOBALS['_ezcImageConverterInstance'])) {
        // Prepare settings for ezcImageConverter
        // Defines the handlers to utilize and auto conversions.
        $settings = new ezcImageConverterSettings(array(new ezcImageHandlerSettings('GD', 'ezcImageGdHandler'), new ezcImageHandlerSettings('ImageMagick', 'ezcImageImagemagickHandler')), array('image/gif' => 'image/png', 'image/bmp' => 'image/jpeg'));
        // Create the converter itself.
        $converter = new ezcImageConverter($settings);
        // Define a transformation
        $filters = array(new ezcImageFilter('scale', array('width' => 100, 'height' => 300, 'direction' => ezcImageGeometryFilters::SCALE_BOTH)), new ezcImageFilter('colorspace', array('space' => ezcImageColorspaceFilters::COLORSPACE_SEPIA)), new ezcImageFilter('border', array('width' => 5, 'color' => array(255, 0, 0))));
        // Which MIME types the conversion may output
        $mimeTypes = array('image/jpeg', 'image/png');
        // Create the transformation inside the manager
        $converter->createTransformation('funny', $filters, $mimeTypes);
        // Assign singleton instance
        $GLOBALS['_ezcImageConverterInstance'] = $converter;
    }
    // Return singleton instance
    return $GLOBALS['_ezcImageConverterInstance'];
}
示例#2
0
 /**
  * Performs the ezcImageConverter transformation
  *
  * @param  string $src Source image
  * @param  string $dst Destination image
  * @return void
  */
 public function perform($src, $dst)
 {
     // fetch the input file locally
     $inClusterHandler = eZClusterFileHandler::instance($src);
     $inClusterHandler->fetch();
     try {
         $this->converter->transform('transformation', $src, $dst);
     } catch (Exception $e) {
         $inClusterHandler->deleteLocal();
         throw $e;
     }
     // store the output file to the cluster
     $outClusterHandler = eZClusterFileHandler::instance();
     // @todo Check if the local output file can be deleted at that stage. Theorically yes.
     $outClusterHandler->fileStore($dst, true);
 }
<?php

require 'ezc-setup.php';
// Setup
$filters = array();
$settings = new ezcImageConverterSettings(array(new ezcImageHandlerSettings('GD', 'ezcImageGdHandler')));
$converter = new ezcImageConverter($settings);
// Create transformation
$filters[] = new ezcImageFilter('croppedThumbnail', array('width' => 128, 'height' => 128));
$converter->createTransformation('doThumbnail', $filters, array('image/png'));
foreach (glob('*.[Jj][Pp][Gg]') as $file) {
    $converter->transform('doThumbnail', $file, "thumbnails/{$file}.png");
}
示例#4
0
 /**
  * Sets the MIME types which are allowed for output.
  *
  * @param array $mime MIME types to allow output for.
  * @return void
  *
  * @throws ezcImageMimeTypeUnsupportedException 
  *         If the MIME types cannot be used as output of any of the 
  *         handlers in the converter.
  */
 protected function setMimeOut(array $mime)
 {
     foreach ($mime as $mimeType) {
         if (!$this->converter->allowsOutput($mimeType)) {
             throw new ezcImageMimeTypeUnsupportedException($mimeType, 'output');
         }
     }
     $this->mimeOut = $mime;
 }
<?php

require_once 'tutorial_autoload.php';
$tutorialPath = dirname(__FILE__);
$settings = new ezcImageConverterSettings(array(new ezcImageHandlerSettings('GD', 'ezcImageGdHandler'), new ezcImageHandlerSettings('ImageMagick', 'ezcImageImagemagickHandler')), array('image/gif' => 'image/png'));
$converter = new ezcImageConverter($settings);
$filters = array(new ezcImageFilter('watermarkAbsolute', array('image' => $tutorialPath . '/img/watermark.png', 'posX' => -52, 'posY' => -25)));
$converter->createTransformation('watermark', $filters, array('image/jpeg', 'image/png'));
try {
    $converter->transform('watermark', $tutorialPath . '/img/imageconversion_example_04_before.jpg', $tutorialPath . '/img/imageconversion_example_04_after.jpg');
} catch (ezcImageTransformationException $e) {
    die("Error transforming the image: <{$e->getMessage()}>");
}
 * General example for the ImageConversion component.
 *
 * @package ImageConversion
 * @version 1.3.5
 * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
 * @license http://ez.no/licenses/new_bsd New BSD License
 */
require_once 'Base/src/base.php';
/**
 * Autoload ezc classes
 *
 * @param string $className
 */
function __autoload($className)
{
    ezcBase::autoload($className);
}
// Prepare settings for ezcImageConverter
// Defines the handlers to utilize and auto conversions.
$settings = new ezcImageConverterSettings(array(new ezcImageHandlerSettings('GD', 'ezcImageGdHandler'), new ezcImageHandlerSettings('ImageMagick', 'ezcImageImagemagickHandler')), array('image/gif' => 'image/png', 'image/bmp' => 'image/jpeg'));
// Create the converter itself.
$converter = new ezcImageConverter($settings);
// Define a transformation
$filters = array(new ezcImageFilter('scaleWidth', array('width' => 100, 'direction' => ezcImageGeometryFilters::SCALE_BOTH)), new ezcImageFilter('colorspace', array('space' => ezcImageColorspaceFilters::COLORSPACE_GREY)));
// Which MIME types the conversion may output
$mimeTypes = array('image/jpeg', 'image/png');
// Create the transformation inside the manager
$converter->createTransformation('thumbnail', $filters, $mimeTypes);
// Transform an image.
$converter->transform('thumbnail', dirname(__FILE__) . '/jpeg.jpg', dirname(__FILE__) . '/jpeg_thumb.jpg');
echo 'Succesfully converted <' . dirname(__FILE__) . '/jpeg.jpg> to <' . dirname(__FILE__) . '/jpeg_thumb.jpg' . ">\n";
示例#7
0
文件: app.php 项目: jeanvoye/utb
 public static function updateAvatar()
 {
     if (isset($_FILES['avatar']) && $_FILES['avatar']['error'] == 0) {
         $q = ezcDbInstance::get()->createSelectQuery();
         $q->select('avatar')->from('avatar')->where($q->expr->eq('user_id', $q->bindValue($_SESSION['ezcAuth_id'])));
         $s = $q->prepare();
         $s->execute();
         $r = $s->fetchAll();
         $settings = new ezcImageConverterSettings(array(new ezcImageHandlerSettings('GD', 'ezcImageGdHandler')));
         $converter = new ezcImageConverter($settings);
         $filters = array(new ezcImageFilter('croppedThumbnail', array('width' => 32, 'height' => 32)));
         $converter->createTransformation('icon', $filters, array('image/png'));
         $converter->transform('icon', $_FILES['avatar']['tmp_name'], $_FILES['avatar']['tmp_name'] . '.tmp.png');
         if (count($r)) {
             $q = ezcDbInstance::get()->createUpdateQuery();
             $q->update('avatar');
             $q->set('avatar', $q->bindValue(base64_encode(file_get_contents($_FILES['avatar']['tmp_name'] . '.tmp.png'))));
             $q->where($q->expr->eq('user_id', $q->bindValue($_SESSION['ezcAuth_id'])));
         } else {
             $q = ezcDbInstance::get()->createInsertQuery();
             $q->insertInto('avatar');
             $q->set('user_id', $q->bindValue($_SESSION['ezcAuth_id']));
             $q->set('avatar', $q->bindValue(base64_encode(file_get_contents($_FILES['avatar']['tmp_name'] . '.tmp.png'))));
         }
         $s = $q->prepare();
         $s->execute();
     }
 }
<?php

require_once 'tutorial_autoload.php';
$tutorialPath = dirname(__FILE__);
$settings = new ezcImageConverterSettings(array(new ezcImageHandlerSettings('GD', 'ezcImageGdHandler'), new ezcImageHandlerSettings('ImageMagick', 'ezcImageImagemagickHandler')));
$converter = new ezcImageConverter($settings);
$filters = array(new ezcImageFilter('scale', array('width' => 320, 'height' => 240, 'direction' => ezcImageGeometryFilters::SCALE_DOWN)));
$converter->createTransformation('preview', $filters, array('image/jpeg'));
try {
    $converter->transform('preview', $tutorialPath . '/img/imageconversion_example_02_before.jpg', $tutorialPath . '/img/imageconversion_example_02_after.jpg');
} catch (ezcImageTransformationException $e) {
    die("Error transforming the image: <{$e->getMessage()}>");
}
示例#9
0
<?php

require 'ezc-setup.php';
$dir = dirname(__FILE__);
// Setup
$filters = array();
$settings = new ezcImageConverterSettings(array(new ezcImageHandlerSettings('GD', 'ezcImageGdHandler')));
$converter = new ezcImageConverter($settings);
// Create transformations
$filters[] = new ezcImageFilter('scale', array('width' => 320, 'height' => 240, 'direction' => ezcImageGeometryFilters::SCALE_DOWN));
$converter->createTransformation('preview', $filters, array('image/jpeg'));
$filters[] = new ezcImageFilter('colorspace', array('space' => ezcImageColorspaceFilters::COLORSPACE_GREY));
$converter->createTransformation('prevgrey', $filters, array('image/jpeg'));