當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Imagick::setImageColorspace方法代碼示例

本文整理匯總了PHP中Imagick::setImageColorspace方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::setImageColorspace方法的具體用法?PHP Imagick::setImageColorspace怎麽用?PHP Imagick::setImageColorspace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Imagick的用法示例。


在下文中一共展示了Imagick::setImageColorspace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: get_average_colour

/**
 * Get the average pixel colour from the given file using Image Magick
 * 
 * @param string $filename
 * @param bool $as_hex      Set to true, the function will return the 6 character HEX value of the colour.    
 *                          If false, an array will be returned with r, g, b components.
 */
function get_average_colour($filename, $as_hex_string = true)
{
    try {
        // Read image file with Image Magick
        $image = new Imagick($filename);
        $image->setImageColorspace(2);
        // Scale down to 1x1 pixel to make Imagick do the average
        $image->scaleimage(1, 1);
        /** @var ImagickPixel $pixel */
        if (!($pixels = $image->getimagehistogram())) {
            return null;
        }
    } catch (ImagickException $e) {
        // Image Magick Error!
        return null;
    } catch (Exception $e) {
        // Unknown Error!
        return null;
    }
    $pixel = reset($pixels);
    $rgb = $pixel->getcolor();
    if ($as_hex_string) {
        return sprintf('%02X%02X%02X', $rgb['r'], $rgb['g'], $rgb['b']);
    }
    return $rgb;
}
開發者ID:rugbyprof,項目名稱:ParkingSpaceIdentifier,代碼行數:33,代碼來源:average_color.php

示例2: applyColorProfiles

 /**
  * this is to force RGB and to apply custom icc color profiles
  */
 protected function applyColorProfiles()
 {
     if ($this->resource->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
         if (self::getCMYKColorProfile() && self::getRGBColorProfile()) {
             $profiles = $this->resource->getImageProfiles('*', false);
             // we're only interested if ICC profile(s) exist
             $has_icc_profile = array_search('icc', $profiles) !== false;
             // if it doesn't have a CMYK ICC profile, we add one
             if ($has_icc_profile === false) {
                 $this->resource->profileImage('icc', self::getCMYKColorProfile());
             }
             // then we add an RGB profile
             $this->resource->profileImage('icc', self::getRGBColorProfile());
             $this->resource->setImageColorspace(Imagick::COLORSPACE_RGB);
         }
     }
     // this is a HACK to force grayscale images to be real RGB - truecolor, this is important if you want to use
     // thumbnails in PDF's because they do not support "real" grayscale JPEGs or PNGs
     // problem is described here: http://imagemagick.org/Usage/basics/#type
     // and here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=6888#p31891
     if ($this->resource->getimagetype() == Imagick::IMGTYPE_GRAYSCALE) {
         $draw = new ImagickDraw();
         $draw->setFillColor("red");
         $draw->setfillopacity(0.001);
         $draw->point(0, 0);
         $this->resource->drawImage($draw);
     }
 }
開發者ID:shanky0110,項目名稱:pimcore-custom,代碼行數:31,代碼來源:Imagick.php

示例3: setColorspaceToRGB

 /**
  * @return $this
  */
 public function setColorspaceToRGB()
 {
     $imageColorspace = $this->resource->getImageColorspace();
     if ($imageColorspace == \Imagick::COLORSPACE_CMYK) {
         if (self::getCMYKColorProfile() && self::getRGBColorProfile()) {
             $profiles = $this->resource->getImageProfiles('*', false);
             // we're only interested if ICC profile(s) exist
             $has_icc_profile = array_search('icc', $profiles) !== false;
             // if it doesn't have a CMYK ICC profile, we add one
             if ($has_icc_profile === false) {
                 $this->resource->profileImage('icc', self::getCMYKColorProfile());
             }
             // then we add an RGB profile
             $this->resource->profileImage('icc', self::getRGBColorProfile());
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
             // we have to use SRGB here, no clue why but it works
         } else {
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
         }
     } else {
         if ($imageColorspace == \Imagick::COLORSPACE_GRAY) {
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
         } else {
             if (!in_array($imageColorspace, array(\Imagick::COLORSPACE_RGB, \Imagick::COLORSPACE_SRGB))) {
                 $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
             } else {
                 // this is to handle embedded icc profiles in the RGB/sRGB colorspace
                 $profiles = $this->resource->getImageProfiles('*', false);
                 $has_icc_profile = array_search('icc', $profiles) !== false;
                 if ($has_icc_profile) {
                     try {
                         // if getImageColorspace() says SRGB but the embedded icc profile is CMYK profileImage() will throw an exception
                         $this->resource->profileImage('icc', self::getRGBColorProfile());
                     } catch (\Exception $e) {
                         \Logger::warn($e);
                     }
                 }
             }
         }
     }
     // this is a HACK to force grayscale images to be real RGB - truecolor, this is important if you want to use
     // thumbnails in PDF's because they do not support "real" grayscale JPEGs or PNGs
     // problem is described here: http://imagemagick.org/Usage/basics/#type
     // and here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=6888#p31891
     $currentLocale = setlocale(LC_ALL, "0");
     // this locale hack thing is also a hack for imagick
     setlocale(LC_ALL, "");
     // details see https://www.pimcore.org/issues/browse/PIMCORE-2728
     $draw = new \ImagickDraw();
     $draw->setFillColor("#ff0000");
     $draw->setfillopacity(0.01);
     $draw->point(floor($this->getWidth() / 2), floor($this->getHeight() / 2));
     // place it in the middle of the image
     $this->resource->drawImage($draw);
     setlocale(LC_ALL, $currentLocale);
     // see setlocale() above, for details ;-)
     return $this;
 }
開發者ID:Gerhard13,項目名稱:pimcore,代碼行數:61,代碼來源:Imagick.php

示例4: newImage

 /**
  * Creates new image instance
  *
  * @param  integer $width
  * @param  integer $height
  * @param  string  $background
  * @return Intervention\Image\Image
  */
 public function newImage($width, $height, $background = null)
 {
     $background = new Color($background);
     // create empty core
     $core = new \Imagick();
     $core->newImage($width, $height, $background->getPixel(), 'png');
     $core->setType(\Imagick::IMGTYPE_UNDEFINED);
     $core->setImagetype(\Imagick::IMGTYPE_UNDEFINED);
     $core->setColorspace(\Imagick::COLORSPACE_UNDEFINED);
     $core->setImageColorspace(\Imagick::COLORSPACE_UNDEFINED);
     // build image
     $image = new \Intervention\Image\Image(new self(), $core);
     return $image;
 }
開發者ID:RHoKAustralia,項目名稱:onaroll21_backend,代碼行數:22,代碼來源:Driver.php

示例5: setColorspaceToRGB

 /**
  * @return $this
  */
 public function setColorspaceToRGB()
 {
     $imageColorspace = $this->resource->getImageColorspace();
     if ($imageColorspace == \Imagick::COLORSPACE_CMYK) {
         if (self::getCMYKColorProfile() && self::getRGBColorProfile()) {
             $profiles = $this->resource->getImageProfiles('*', false);
             // we're only interested if ICC profile(s) exist
             $has_icc_profile = array_search('icc', $profiles) !== false;
             // if it doesn't have a CMYK ICC profile, we add one
             if ($has_icc_profile === false) {
                 $this->resource->profileImage('icc', self::getCMYKColorProfile());
             }
             // then we add an RGB profile
             $this->resource->profileImage('icc', self::getRGBColorProfile());
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
             // we have to use SRGB here, no clue why but it works
         } else {
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
         }
     } else {
         if ($imageColorspace == \Imagick::COLORSPACE_GRAY) {
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
         } else {
             if (!in_array($imageColorspace, array(\Imagick::COLORSPACE_RGB, \Imagick::COLORSPACE_SRGB))) {
                 $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
             } else {
                 // this is to handle embedded icc profiles in the RGB/sRGB colorspace
                 $profiles = $this->resource->getImageProfiles('*', false);
                 $has_icc_profile = array_search('icc', $profiles) !== false;
                 if ($has_icc_profile) {
                     $this->resource->profileImage('icc', self::getRGBColorProfile());
                 }
             }
         }
     }
     // this is a HACK to force grayscale images to be real RGB - truecolor, this is important if you want to use
     // thumbnails in PDF's because they do not support "real" grayscale JPEGs or PNGs
     // problem is described here: http://imagemagick.org/Usage/basics/#type
     // and here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=6888#p31891
     $draw = new \ImagickDraw();
     $draw->setFillColor("#ff0000");
     $draw->setfillopacity(0.01);
     $draw->point(floor($this->getWidth() / 2), floor($this->getHeight() / 2));
     // place it in the middle of the image
     $this->resource->drawImage($draw);
     return $this;
 }
開發者ID:pawansgi92,項目名稱:pimcore2,代碼行數:50,代碼來源:Imagick.php

示例6: Imagick

 function encode_imagick($ps_filepath, $ps_output_path, $pa_options)
 {
     if (!($magick = $this->mimetype2magick[$pa_options["output_mimetype"]])) {
         $this->error = "Invalid output format";
         return false;
     }
     #
     # Open image
     #
     $h = new Imagick();
     if (!$h->readImage($ps_filepath)) {
         $this->error = "Couldn't open image {$ps_filepath}";
         return false;
     }
     if (function_exists('exif_read_data')) {
         if (is_array($va_exif = @exif_read_data($ps_filepath, 'EXIF', true, false))) {
             if (isset($va_exif['IFD0']['Orientation'])) {
                 $vn_orientation = $va_exif['IFD0']['Orientation'];
                 switch ($vn_orientation) {
                     case 3:
                         $h->rotateImage("#FFFFFF", 180);
                         break;
                     case 6:
                         $h->rotateImage("#FFFFFF", 90);
                         break;
                     case 8:
                         $h->rotateImage("#FFFFFF", -90);
                         break;
                 }
             }
         }
     }
     $h->setImageType(imagick::IMGTYPE_TRUECOLOR);
     if (!$h->setImageColorspace(imagick::COLORSPACE_RGB)) {
         $this->error = "Error during RGB colorspace transformation operation";
         return false;
     }
     $va_tmp = $h->getImageGeometry();
     $image_width = $va_tmp['width'];
     $image_height = $va_tmp['height'];
     if ($image_width < 10 || $image_height < 10) {
         $this->error = "Image is too small to be output as Tilepic; minimum dimensions are 10x10 pixels";
         return false;
     }
     if ($pa_options["scale_factor"] != 1) {
         $image_width *= $pa_options["scale_factor"];
         $image_height *= $pa_options["scale_factor"];
         if (!$h->resizeImage($image_width, $image_height, imagick::FILTER_CUBIC, $pa_options["antialiasing"])) {
             $this->error = "Couldn't scale image";
             return false;
         }
     }
     #
     # How many layers to make?
     #
     if (!$pa_options["layers"]) {
         $sw = $image_width * $pa_options["layer_ratio"];
         $sh = $image_height * $pa_options["layer_ratio"];
         $pa_options["layers"] = 1;
         while ($sw >= $pa_options["tile_width"] || $sh >= $pa_options["tile_height"]) {
             $sw = ceil($sw / $pa_options["layer_ratio"]);
             $sh = ceil($sh / $pa_options["layer_ratio"]);
             $pa_options["layers"]++;
         }
     }
     #
     # Cut image into tiles
     #
     $tiles = 0;
     $layer_list = array();
     $base_width = $image_width;
     $base_height = $image_height;
     if ($this->debug) {
         print "BASE {$base_width} x {$base_height} \n";
     }
     for ($l = $pa_options["layers"]; $l >= 1; $l--) {
         $x = $y = 0;
         $wx = $pa_options["tile_width"];
         $wy = $pa_options["tile_height"];
         if ($this->debug) {
             print "LAYER={$l}\n";
         }
         if ($l < $pa_options["layers"]) {
             $image_width = ceil($image_width / $pa_options["layer_ratio"]);
             $image_height = ceil($image_height / $pa_options["layer_ratio"]);
             if ($this->debug) {
                 print "RESIZE layer {$l} TO {$image_width} x {$image_height} \n";
             }
             if (!$h->resizeImage($image_width, $image_height, imagick::FILTER_CUBIC, $pa_options["antialiasing"])) {
                 $this->error = "Couldn't scale image";
                 return false;
             }
         }
         $i = 0;
         $layer_list[] = array();
         while ($y < $image_height) {
             if (!($slice = $h->getImageRegion($wx, $wy, $x, $y))) {
                 $this->error = "Couldn't create tile";
                 return false;
             }
//.........這裏部分代碼省略.........
開發者ID:guaykuru,項目名稱:pawtucket,代碼行數:101,代碼來源:TilepicParser.php

示例7: array

} else {
    Logger::debug('main', '(client/applications) No Session id nor public_webservices_access');
    echo return_error(7, 'No Session id nor public_webservices_access');
    die;
}
$applicationDB = ApplicationDB::getInstance();
$applications = $applicationDB->getApplicationsWithMimetype($_GET['id']);
$apps = array();
foreach ($applications as $application) {
    if (!$application->haveIcon()) {
        continue;
    }
    $score = count($application->groups());
    if ($application->getAttribute('type') == 'windows') {
        $score += 10;
    }
    $apps[$score] = $application;
}
header('Content-Type: image/png');
$first = new Imagick(realpath(dirname(__FILE__) . '/../admin/media/image/empty.png'));
if (!is_array($apps) || count($apps) == 0) {
    echo $first;
    die;
}
arsort($apps);
$application = array_shift($apps);
$second = new Imagick(realpath($application->getIconPath()));
$second->scaleImage(16, 16);
$first->setImageColorspace($second->getImageColorspace());
$first->compositeImage($second, $second->getImageCompose(), 6, 10);
echo $first;
開發者ID:bloveing,項目名稱:openulteo,代碼行數:31,代碼來源:mimetype-icon.php

示例8: grayImage

 function grayImage($imagePath)
 {
     $image = new Imagick();
     $image->readImage('../uploads/' . $imagePath);
     $image->setImageColorspace(2);
     $image->writeImage('../uploads/' . $imagePath);
 }
開發者ID:Flasheur111,項目名稱:420px,代碼行數:7,代碼來源:ImageController.php

示例9: basename

<?php

$target_dir = "/var/www/html/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
// Check if image file is a actual image or fake image
if (isset($_POST["submit"])) {
    $target_dir = "/var/www/html/";
    $target_file = $target_dir . basename($_FILES["file"]["name"]);
    move_uploaded_file($_FILES["file"]["tmp_name"], $target_file);
    // Imagemagick stuff for exploiting
    // push graphic-context
    // viewbox 0 0 640 480
    // fill 'url(https://voidsec1.com/logo.png"|touch "/tmp/passwd)'
    // pop graphic-context
    $im = new Imagick(realpath($target_file));
    $im->setImageColorspace(255);
    $im->setCompression(Imagick::COMPRESSION_JPEG);
    $im->setCompressionQuality(60);
    $im->setImageFormat('jpeg');
    echo "The file " . basename($_FILES["file"]["name"]) . " has been uploaded.";
}
開發者ID:0xcc-labs,項目名稱:Exploit-POCs,代碼行數:21,代碼來源:upload.php

示例10: Imagen__CrearMiniatura

function Imagen__CrearMiniatura($Origen, $Destino, $Ancho = 100, $Alto = 100)
{
    $im = new Imagick($Origen);
    $im->setImageColorspace(255);
    $im->setCompression(Imagick::COMPRESSION_JPEG);
    $im->setCompressionQuality(80);
    $im->setImageFormat('jpeg');
    list($newX, $newY) = scaleImage($im->getImageWidth(), $im->getImageHeight(), $Ancho, $Alto);
    $im->thumbnailImage($newX, $newY, false);
    return $im->writeImage($Destino);
}
開發者ID:vlad88sv,項目名稱:BCA,代碼行數:11,代碼來源:__stubs.php

示例11: convert

 /**
  * Convert image to a given type
  *
  * @param int    $type     Destination file type (see class constants)
  * @param string $filename Output filename (if empty, original file will be used
  *                         and filename extension will be modified)
  *
  * @return bool True on success, False on failure
  */
 public function convert($type, $filename = null)
 {
     $rcube = rcube::get_instance();
     $convert = $rcube->config->get('im_convert_path', false);
     if (!$filename) {
         $filename = $this->image_file;
         // modify extension
         if ($extension = self::$extensions[$type]) {
             $filename = preg_replace('/\\.[^.]+$/', '', $filename) . '.' . $extension;
         }
     }
     // use ImageMagick in command line
     if ($convert) {
         $p['in'] = $this->image_file;
         $p['out'] = $filename;
         $p['type'] = self::$extensions[$type];
         $result = rcube::exec($convert . ' 2>&1 -colorspace sRGB -strip -quality 75 {in} {type}:{out}', $p);
         if ($result === '') {
             chmod($filename, 0600);
             return true;
         }
     }
     // use PHP's Imagick class
     if (class_exists('Imagick', false)) {
         try {
             $image = new Imagick($this->image_file);
             $image->setImageColorspace(Imagick::COLORSPACE_SRGB);
             $image->setImageCompressionQuality(75);
             $image->setImageFormat(self::$extensions[$type]);
             $image->stripImage();
             if ($image->writeImage($filename)) {
                 @chmod($filename, 0600);
                 return true;
             }
         } catch (Exception $e) {
             rcube::raise_error($e, true, false);
         }
     }
     // use GD extension (TIFF isn't supported)
     $props = $this->props();
     // do we have enough memory? (#1489937)
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' && !$this->mem_check($props)) {
         return false;
     }
     if ($props['gd_type']) {
         if ($props['gd_type'] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) {
             $image = imagecreatefromjpeg($this->image_file);
         } else {
             if ($props['gd_type'] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) {
                 $image = imagecreatefromgif($this->image_file);
             } else {
                 if ($props['gd_type'] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')) {
                     $image = imagecreatefrompng($this->image_file);
                 } else {
                     // @TODO: print error to the log?
                     return false;
                 }
             }
         }
         if ($type == self::TYPE_JPG) {
             $result = imagejpeg($image, $filename, 75);
         } else {
             if ($type == self::TYPE_GIF) {
                 $result = imagegif($image, $filename);
             } else {
                 if ($type == self::TYPE_PNG) {
                     $result = imagepng($image, $filename, 6, PNG_ALL_FILTERS);
                 }
             }
         }
         if ($result) {
             @chmod($filename, 0600);
             return true;
         }
     }
     // @TODO: print error to the log?
     return false;
 }
開發者ID:jimjag,項目名稱:roundcubemail,代碼行數:87,代碼來源:rcube_image.php

示例12: postRequestAtLocal

 /**
  * [postRequestAtLocal 上傳圖片  擴展(待完善)]  
  * @param  array  $img_info [圖片上傳信息]
  * @param  [type] $rel_path [生成的路徑 ]
  * @return [type]           [description]
  */
 public function postRequestAtLocal($img_info = array(), $rel_path = null)
 {
     if (empty($img_info) || !$rel_path) {
         return false;
     }
     $full_path = self::LOCAL_PATH . '/' . $rel_path;
     $rdir = dirname($full_path);
     if (!file_exists($rdir)) {
         $oldumask = umask(0);
         mkdir($rdir, 0777, TRUE);
         chmod($rdir, 0777);
         umask($oldumask);
     }
     // Step 3:圖片處理
     $compress = empty($_GET['compress']) || $_GET['cmopress'] != 'n' ? 'y' : $_GET['compress'];
     $im = new Imagick();
     try {
         $im->readImageBlob(file_get_contents($img_info['tmp_name']));
     } catch (Exception $e) {
         die($e->getMessage());
     }
     // 獲取圖片格式
     $image_format = strtoupper($im->getImageFormat());
     switch ($image_format) {
         case 'PNG':
             $new_name = $full_path . self::DEFAULT_SUFFIX;
             $full_path .= ".png";
             $im->setImageColorspace(Imagick::COLORSPACE_RGB);
             $im->setImageFormat("PNG") or die("Error:");
             if ($compress != "n") {
                 $im->setCompressionQuality(80) or die("Error:");
             }
             $im->writeImage($full_path) or die("Error:");
             rename($full_path, $new_name);
             $full_path = $new_name;
             $type = "image/png";
             break;
         case 'GIF':
             $new_name = $full_path . self::DEFAULT_SUFFIX;
             $full_path .= ".gif";
             $im->setImageColorspace(Imagick::COLORSPACE_RGB);
             $im->setImageFormat("GIF") or die("Error:");
             if ($compress != "n") {
                 $im->setCompressionQuality(80) or die("Error:");
             }
             $im->writeImage($full_path, TRUE) or die("Error:");
             rename($full_path, $new_name);
             $full_path = $new_name;
             $type = "image/gif";
             break;
         default:
             $full_path .= self::DEFAULT_SUFFIX;
             $im->setImageColorspace(imagick::COLORSPACE_RGB);
             $im->setImageFormat("JPG") or die("Error:");
             if ($compress != "n") {
                 $im->setCompression(Imagick::COMPRESSION_JPEG) or die("Error:");
                 $im->setCompressionQuality(80) or die("Error:");
             }
             $im->writeImage($full_path) or die("Error:");
             $type = "image/jpeg";
             break;
     }
 }
開發者ID:hewangxu,項目名稱:hmevent,代碼行數:69,代碼來源:oss.class.php

示例13: imgSquareFit

 /**
  * Put image to square
  *
  * @param  string $path image file
  * @param  int $width square width
  * @param  int $height square height
  * @param int|string $align reserved
  * @param int|string $valign reserved
  * @param  string $bgcolor square background color in #rrggbb format
  * @param  string $destformat image destination format
  * @param  int $jpgQuality JEPG quality (1-100)
  * @return false|string
  * @author Dmitry (dio) Levashov
  * @author Alexey Sukhotin
  */
 protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null, $jpgQuality = null)
 {
     if (($s = getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     /* Coordinates for image over square aligning */
     $y = ceil(abs($height - $s[1]) / 2);
     $x = ceil(abs($width - $s[0]) / 2);
     if (!$jpgQuality) {
         $jpgQuality = $this->options['jpgQuality'];
     }
     elFinder::extendTimeLimit(300);
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             if ($bgcolor === 'transparent') {
                 $bgcolor = 'rgba(255, 255, 255, 0.0)';
             }
             $ani = $img->getNumberImages() > 1;
             if ($ani && is_null($destformat)) {
                 $img1 = new Imagick();
                 $img1->setFormat('gif');
                 $img = $img->coalesceImages();
                 do {
                     $gif = new Imagick();
                     $gif->newImage($width, $height, new ImagickPixel($bgcolor));
                     $gif->setImageColorspace($img->getImageColorspace());
                     $gif->setImageFormat('gif');
                     $gif->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
                     $gif->setImageDelay($img->getImageDelay());
                     $gif->setImageIterations($img->getImageIterations());
                     $img1->addImage($gif);
                     $gif->clear();
                 } while ($img->nextImage());
                 $img1 = $img1->optimizeImageLayers();
                 $result = $img1->writeImages($path, true);
             } else {
                 if ($ani) {
                     $img->setFirstIterator();
                 }
                 $img1 = new Imagick();
                 $img1->newImage($width, $height, new ImagickPixel($bgcolor));
                 $img1->setImageColorspace($img->getImageColorspace());
                 $img1->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
                 $result = $this->imagickImage($img1, $path, $destformat, $jpgQuality);
             }
             $img1->clear();
             $img->clear();
             return $result ? $path : false;
             break;
         case 'convert':
             extract($this->imageMagickConvertPrepare($path, $destformat, $jpgQuality, $s));
             if ($bgcolor === 'transparent') {
                 $bgcolor = 'rgba(255, 255, 255, 0.0)';
             }
             $cmd = sprintf('convert -size %dx%d "xc:%s" png:- | convert%s%s png:-  %s -geometry +%d+%d -compose over -composite%s %s', $width, $height, $bgcolor, $coalesce, $jpgQuality, $quotedPath, $x, $y, $deconstruct, $quotedDstPath);
             $result = false;
             if ($this->procExec($cmd) === 0) {
                 $result = true;
             }
             return $result ? $path : false;
             break;
         case 'gd':
             $img = $this->gdImageCreate($path, $s['mime']);
             if ($img && false != ($tmp = imagecreatetruecolor($width, $height))) {
                 $this->gdImageBackground($tmp, $bgcolor);
                 if ($bgcolor === 'transparent' && ($destformat === 'png' || $s[2] === IMAGETYPE_PNG)) {
                     $bgNum = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
                     imagefill($tmp, 0, 0, $bgNum);
                 }
                 if (!imagecopy($tmp, $img, $x, $y, 0, 0, $s[0], $s[1])) {
                     return false;
                 }
                 $result = $this->gdImage($tmp, $path, $destformat, $s['mime'], $jpgQuality);
                 imagedestroy($img);
                 imagedestroy($tmp);
                 return $result ? $path : false;
             }
             break;
     }
//.........這裏部分代碼省略.........
開發者ID:bigbrush,項目名稱:yii2-big,代碼行數:101,代碼來源:elFinderVolumeDriver.class.php

示例14: Imagick

 function _mkbilder($typ)
 {
     $handle = new Imagick();
     $img = new Imagick();
     if (!$handle->readImage("/tmp/tmp.file_org")) {
         return false;
     }
     $d = $handle->getImageGeometry();
     if ($d["width"] < $d["height"]) {
         $h = true;
         $faktor = 1 / ($d["height"] / $d["width"]);
     } else {
         $h = false;
         $faktor = $d["width"] / $d["height"];
     }
     $img->newImage($this->smallwidth, $this->smallheight, new ImagickPixel('white'));
     $img->setImageFormat($typ);
     $smallheight = floor($this->smallwidth * $faktor);
     $handle->thumbnailImage($this->smallwidth, $smallheight, true);
     $img->setImageColorspace($handle->getImageColorspace());
     $img->compositeImage($handle, imagick::GRAVITY_CENTER, 0, 0);
     $img->compositeImage($handle, $handle->getImageCompose(), 0, 0);
     $handle->clear();
     $handle->destroy();
     $rc = $img->writeImage("/tmp/tmp.file_small");
     $img->clear();
     $img->destroy();
     if (!$this->original) {
         $handle = new Imagick();
         $img->newImage($this->bigwidth, $this->bigheight, new ImagickPixel('white'));
         $img->setImageFormat($typ);
         $handle->readImage("/tmp/tmp.file_org");
         $bigheight = floor($this->bigwidth * $faktor);
         $handle->thumbnailImage($this->bigwidth, $bigheight, true);
         $img->compositeImage($handle, imagick::GRAVITY_CENTER, 0, 0);
         $handle->clear();
         $handle->destroy();
         return $img->writeImage("/tmp/tmp.file_org");
         $img->clear();
         $img->destroy();
     }
     return $rc;
 }
開發者ID:vanloswang,項目名稱:kivitendo-crm,代碼行數:43,代碼來源:Picture.php

示例15: createThumb

 private function createThumb($url, $filename, $type, $width, $height)
 {
     # Function that uses avconv to generate a thumbnail for a video file
     # Expects the following:
     # (string) $url : the path to the original video file
     # (string) $filename : the filename without path
     # (string) $type : dunno why this is needed right now, only mp4 is supported
     # (int) $width
     # (int) $height
     # Returns the following:
     # (bool) $return : true on success, false otherwise
     # Check dependencies
     self::dependencies(isset($this->database, $url, $filename, $this->settings, $type, $width, $height));
     # Call Plugins
     $this->plugins(__METHOD__, 0, func_get_args());
     #First step is to take a frame from the video which will then be resized
     $videoName = explode('.', $filename);
     $thumbOriginalName = $videoName[0] . "@original.jpg";
     $thumbOriginalPath = LYCHEE_UPLOADS_THUMB . $thumbOriginalName;
     $command = "avconv  -itsoffset -4  -i " . $url . " -vcodec mjpeg -vframes 1 -an -f rawvideo -s " . $width . "x" . $height . " " . $thumbOriginalPath;
     Log::notice($this->database, __METHOD__, __LINE__, "Command: " . $command);
     exec($command);
     # Next create the actual thumbnails using the same code as used for photos
     # Size of the thumbnail
     $newWidth = 200;
     $newHeight = 200;
     $iconWidth = 50;
     $iconHeight = 50;
     $videoName = explode('.', $filename);
     $newUrl = LYCHEE_UPLOADS_THUMB . $videoName[0] . '.jpeg';
     $newUrl2x = LYCHEE_UPLOADS_THUMB . $videoName[0] . '@2x.jpeg';
     # Create thumbnails with Imagick
     if (extension_loaded('imagick') && $this->settings['imagick'] === '1') {
         # Read icon image first
         $icon = new Imagick(LYCHEE . "/src/images/icon_play_overlay.png");
         # Read image
         $thumb = new Imagick();
         $thumb->readImage($thumbOriginalPath);
         $thumb->setImageCompressionQuality($this->settings['thumbQuality']);
         $thumb->setImageFormat('jpeg');
         #Set the colorspace of the icon to the same as the image
         $icon->setImageColorspace($thumb->getImageColorspace());
         # Copy image for 2nd thumb version
         $thumb2x = clone $thumb;
         $icon2x = clone $icon;
         # Create 1st version
         $thumb->cropThumbnailImage($newWidth, $newHeight);
         #Composite the icon
         $icon->cropThumbnailImage($iconWidth, $iconHeight);
         $thumb->compositeImage($icon, imagick::COMPOSITE_DEFAULT, $newWidth / 2 - $iconWidth / 2, $newHeight / 2 - $iconHeight / 2);
         #Save the small thumbnail
         $thumb->writeImage($newUrl);
         $thumb->clear();
         $thumb->destroy();
         # Create 2nd version
         $thumb2x->cropThumbnailImage($newWidth * 2, $newHeight * 2);
         # Composite the icon
         $icon2x->cropThumbnailImage($iconWidth * 2, $iconHeight * 2);
         $thumb2x->compositeImage($icon2x, imagick::COMPOSITE_DEFAULT, $newWidth - $iconWidth, $newHeight - $iconHeight);
         $thumb2x->writeImage($newUrl2x);
         $thumb2x->clear();
         $thumb2x->destroy();
     } else {
         # Read icon image first
         $iconPath = LYCHEE . "/src/images/icon_play_overlay.png";
         $iconSize = getimagesize($iconPath);
         $icon = imagecreatetruecolor($iconSize[0], $iconSize[1]);
         # Create image
         $thumb = imagecreatetruecolor($newWidth, $newHeight);
         $thumb2x = imagecreatetruecolor($newWidth * 2, $newHeight * 2);
         # Set position
         if ($width < $height) {
             $newSize = $width;
             $startWidth = 0;
             $startHeight = $height / 2 - $width / 2;
         } else {
             $newSize = $height;
             $startWidth = $width / 2 - $height / 2;
             $startHeight = 0;
         }
         # Create new image
         $sourceImg = imagecreatefromjpeg($thumbOriginalPath);
         $sourceIcon = imagecreatefrompng($iconPath);
         # Create thumb
         fastimagecopyresampled($thumb, $sourceImg, 0, 0, $startWidth, $startHeight, $newWidth, $newHeight, $newSize, $newSize);
         fastimagecopyresampled($thumb, $sourceIcon, $newWidth / 2 - $iconWidth / 2, $newHeight / 2 - $iconHeight / 2, 0, 0, $iconWidth, $iconHeight, $iconSize[0], $iconSize[1]);
         imagejpeg($thumb, $newUrl, $this->settings['thumbQuality']);
         imagedestroy($thumb);
         # Create retina thumb
         fastimagecopyresampled($thumb2x, $sourceImg, 0, 0, $startWidth, $startHeight, $newWidth * 2, $newHeight * 2, $newSize, $newSize);
         fastimagecopyresampled($thumb2x, $sourceIcon, $newWidth - $iconWidth, $newHeight - $iconHeight, 0, 0, $iconWidth * 2, $iconHeight * 2, $iconSize[0], $iconSize[1]);
         imagejpeg($thumb2x, $newUrl2x, $this->settings['thumbQuality']);
         imagedestroy($thumb2x);
         # Free memory
         imagedestroy($sourceImg);
         imagedestroy($sourceIcon);
     }
     # Finally delete the original thumbnail frame
     unlink($thumbOriginalPath);
     return true;
//.........這裏部分代碼省略.........
開發者ID:thejandroman,項目名稱:Lychee,代碼行數:101,代碼來源:Video.php


注:本文中的Imagick::setImageColorspace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。