예제 #1
0
 function &create(&$root, &$pipeline)
 {
     $name = $root->get_attribute('name');
     $value = $root->get_attribute('value');
     $url_autofix = new AutofixUrl();
     $src = $url_autofix->apply(trim($root->get_attribute("src")));
     $src_img = ImageFactory::get($pipeline->guess_url($src), $pipeline);
     if (is_null($src_img)) {
         error_log(sprintf("Cannot open image at '%s'", $src));
         if ($root->has_attribute('width')) {
             $width = px2pt($root->get_attribute('width'));
         } else {
             $width = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX);
         }
         if ($root->has_attribute('height')) {
             $height = px2pt($root->get_attribute('height'));
         } else {
             $height = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX);
         }
         $alt = $root->get_attribute('alt');
         $css_state =& $pipeline->get_current_css_state();
         $box =& new ButtonBrokenImagebox($width, $height, $alt, $name, $value, $css_state->get_property(CSS_HTML2PS_FORM_ACTION));
         $box->readCSS($css_state);
         return $box;
     }
     $css_state =& $pipeline->get_current_css_state();
     $box =& new ButtonImageBox($src_img, $name, $value, $css_state->get_property(CSS_HTML2PS_FORM_ACTION));
     $box->readCSS($css_state);
     $box->_setupSize();
     return $box;
 }
 protected function _getImageLibrary()
 {
     if ($this->_image_library) {
         return $this->_image_library;
     }
     include_once LIMB_DIR . '/class/lib/image/ImageFactory.class.php';
     $this->_image_library = ImageFactory::create();
     return $this->_image_library;
 }
예제 #3
0
 function get($url, &$pipeline)
 {
     global $g_config, $g_image_cache;
     if (!$g_config['renderimages']) {
         return null;
     }
     // Check if this URL have been cached
     //
     if (isset($g_image_cache[$url])) {
         //      return do_image_open($g_image_cache[$url]);
         return $g_image_cache[$url];
     }
     // Download image; we should do it before we call do_image_open,
     // as it tries to open image file twice: first to determine image type
     // and second to actually create the image - PHP url wrappers do no caching
     // at all
     //
     $filename = ImageFactory::make_cache_filename($url);
     // REQUIRES: PHP 4.3.0+
     // we suppress warning messages, as missing image files will cause 'copy' to print
     // several warnings
     //
     // @TODO: change to fetcher class call
     //
     // simplify our url by fetcher simlify functionality
     $url = FetcherUrl::_simplify_path($url);
     $data = $pipeline->fetch($url);
     if (is_null($data)) {
         trigger_error("Cannot fetch image: " . $url, E_USER_WARNING);
         return null;
     }
     $file = fopen($filename, 'wb');
     fwrite($file, $data->content);
     fclose($file);
     $pipeline->pop_base_url();
     // register it in the cached objects array
     //
     $handle = do_image_open($filename, $type);
     if ($handle) {
         $g_image_cache[$url] =& new Image($handle, $filename, $type);
     } else {
         $g_image_cache[$url] = null;
     }
     // return image
     //
     // return do_image_open($filename);
     return $g_image_cache[$url];
 }
 function parse($value, &$pipeline)
 {
     global $g_config;
     if (!$g_config['renderimages']) {
         return CSSBackgroundImage::default_value();
     }
     if ($value === 'inherit') {
         return CSS_PROPERTY_INHERIT;
     }
     // 'url' value
     if (preg_match("/url\\((.*[^\\\\]?)\\)/is", $value, $matches)) {
         $url = $matches[1];
         $full_url = $pipeline->guess_url(css_remove_value_quotes($url));
         return new BackgroundImage($full_url, ImageFactory::get($full_url, $pipeline));
     }
     // 'none' and unrecognzed values
     return CSSBackgroundImage::default_value();
 }
 function parse($value, &$pipeline)
 {
     if ($value === 'inherit') {
         return CSS_PROPERTY_INHERIT;
     }
     global $g_config;
     if (!$g_config['renderimages']) {
         return CSSListStyleImage::default_value();
     }
     if (preg_match('/url\\(([^)]+)\\)/', $value, $matches)) {
         $url = $matches[1];
         $full_url = $pipeline->guess_url(css_remove_value_quotes($url));
         return new ListStyleImage($full_url, ImageFactory::get($full_url, $pipeline));
     }
     /**
      * 'none' value and all unrecognized values
      */
     return CSSListStyleImage::default_value();
 }
 function &create(&$root, &$pipeline)
 {
     // Open image referenced by HTML tag
     // Some crazy HTML writers add leading and trailing spaces to SRC attribute value - we need to remove them
     //
     $url_autofix = new AutofixUrl();
     $src = $url_autofix->apply(trim($root->get_attribute("src")));
     $image_url = $pipeline->guess_url($src);
     $src_img = ImageFactory::get($image_url, $pipeline);
     if (is_null($src_img)) {
         // image could not be opened, use ALT attribute
         if ($root->has_attribute('width')) {
             $width = px2pt($root->get_attribute('width'));
         } else {
             $width = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX);
         }
         if ($root->has_attribute('height')) {
             $height = px2pt($root->get_attribute('height'));
         } else {
             $height = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX);
         }
         $alt = $root->get_attribute('alt');
         $box =& new BrokenImgBox($width, $height, $alt);
         $box->readCSS($pipeline->getCurrentCSSState());
         $box->put_width($width);
         $box->put_height($height);
         $box->default_baseline = $box->get_full_height();
         $box->src_height = $box->get_height();
         $box->src_width = $box->get_width();
         return $box;
     } else {
         $box =& new ImgBox($src_img);
         $box->readCSS($pipeline->getCurrentCSSState());
         $box->_setupSize();
         return $box;
     }
 }
예제 #7
0
    }
    public function getData()
    {
        return $this->data;
    }
}
// 工厂模式 指代在某一个
class ImageFactory
{
    public static function factory($file)
    {
        $pathParts = pathinfo($file);
        switch (strtolower($pathParts['extension'])) {
            case 'jpg':
                $ret = new Image_Jpeg($file);
                break;
            case 'png':
                $ret = new Image_Png($file);
                break;
            default:
                break;
        }
        if ($ret instanceof IImage) {
            return $ret;
        } else {
            echo '错误';
        }
    }
}
$image = ImageFactory::factory("./my.png");
echo $image->getWidth();
예제 #8
0
    {
        $this->type = 'png';
    }
}
class OtherType extends ImageType
{
    function __construct($fileName)
    {
        $this->type = 'неизвестен';
    }
}
class ImageFactory
{
    static function checkType($fileName)
    {
        if (strpos($fileName, '.gif')) {
            return new GIFType($fileName);
        } elseif (strpos($fileName, '.jpg')) {
            return new JPGType($fileName);
        } elseif (strpos($fileName, '.png')) {
            return new PNGType($fileName);
        } else {
            return new OtherType($fileName);
        }
    }
}
$fileNames = array('test.jpg', 'test.txt', 'test.gif', 'test.png');
foreach ($fileNames as $fileName) {
    print "Тип файла " . $fileName . " ";
    print ImageFactory::checkType($fileName)->returnType() . ".<br>";
}
예제 #9
0
 function close()
 {
     $this->_dispatcher->fire('after-batch', array('pipeline' => &$this));
     $this->output_driver->close();
     $this->_output();
     $this->output_driver->release();
     // Non HTML-specific cleanup
     //
     ImageFactory::clear_cache();
 }
예제 #10
0
        }
        //The scheme is not defined and original file is not here, file does not exists
    } else {
        header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404);
        exit;
    }
}
//If resized folder does not exists we add it
if (!is_dir($sResizedDir)) {
    $umask = umask(0);
    mkdir($sResizedDir, 0777, true);
    umask($umask);
}
try {
    require_once dirname(__FILE__) . '/src/Image/ImageFactory.php';
    $oResized = ImageFactory::build($sOriginalFile);
    if (!is_file($sResizedFile)) {
        //Resize on width constraint only
        if (strpos($_GET['format'], 'w') === 0) {
            $oResized->resize(substr($_GET['format'], 1));
            //Resize on height constraint only
        } elseif (strpos($_GET['format'], 'h') === 0) {
            $oResized->resize(null, substr($_GET['format'], 1));
            //Resize and crop (11x11)
        } else {
            $aFormat = explode('x', $_GET['format']);
            //Use built Image manipulator to resize and save the new file
            $oResized->resizeAndCrop($aFormat[0], $aFormat[1]);
        }
        $oResized->save($sResizedFile);
    }
예제 #11
0
파일: exemple.php 프로젝트: moust/paint
<?php

require_once __DIR__ . '/vendor/autoload.php';
$image = new Paint\Image('tests/carlos.jpeg');
$image->addTransformation(new Transformation\Crop(300, 200));
$image->addFilter(new Paint\Filter\FilterGrayscale());
$image->generate(new Paint\Format\JPEG(60), 'tests/destination.jpeg');
$factory = ImageFactory::create('tests/carlos.jpeg');
$factory->addTransformation(new Transformation\Crop(300, 200));
$factory->addFilter(new Filter\FilterGrayscale());
$factory->generate('jpeg', 'tests/destination.jpg');
예제 #12
0
        // If false, send browser header for output to browser window
        if ($SetFileName == false) {
            header('Content-Type: ' . $this->original['type']);
        }
        // Output proper image type
        if ($this->original['type'] == 'image/gif') {
            imagegif($tmp_img);
        } elseif ($this->original['type'] == 'image/png') {
            $SetFileName !== false ? imagepng($tmp_img, $SetFileName, $quality) : imagepng($tmp_img);
        } elseif ($this->original['type'] == 'image/jpeg') {
            $SetFileName !== false ? imagejpeg($tmp_img, $SetFileName, $quality) : imagejpeg($tmp_img);
        }
        // Destroy set images
        if (isset($thumb_img)) {
            imagedestroy($thumb_img);
        }
        // Destroy image
        if (isset($tmp_img)) {
            imagedestroy($tmp_img);
        }
    }
}
// Initiate class
$ImageMaker = new ImageFactory();
// Here is just a test landscape sized image
$thumb_target = '5ff4d6b8aade359acaba3fc5bdd930db.jpg';
// This will save the file to disk. $destination is where the file will save and with what name
$destination = '5ff4d6b8aade359acaba3fc5bdd930db_120x120.jpg';
$ImageMaker->Thumbnailer($thumb_target, 120, 120, $destination);
// This example will just display to browser, not save to disk
// $ImageMaker->Thumbnailer($thumb_target,120,120);
예제 #13
0
 /**
  * Opens an image file.
  * 
  * @deprecated This function is deprecated, use load_image() 
  * with the colorize, ignoremask, invert, mask, masked, and page 
  * options instead.
  * 
  * @param string $imagetype
  * @param string $filename
  * @param string $stringparam
  * @param integer $intparam
  * @return AbstractImage
  */
 public function open_image_file($imagetype, $filename, $stringparam = '', $intparam = 0)
 {
     return ImageFactory::factory($filename);
 }