本文整理匯總了PHP中Imagick::setInterlaceScheme方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::setInterlaceScheme方法的具體用法?PHP Imagick::setInterlaceScheme怎麽用?PHP Imagick::setInterlaceScheme使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::setInterlaceScheme方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: IMAGEN_tipo_normal
function IMAGEN_tipo_normal()
{
$escalado = 'IMG/i/m/' . $_GET['ancho'] . '_' . $_GET['alto'] . '_' . $_GET['sha1'];
$origen = 'IMG/i/' . $_GET['sha1'];
$ancho = $_GET['ancho'];
$alto = $_GET['alto'];
if (@($ancho * $alto) > 562500) {
die('La imagen solicitada excede el límite de este servicio');
}
if (!file_exists($escalado)) {
$im = new Imagick($origen);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(85);
$im->setImageFormat('jpeg');
$im->stripImage();
$im->despeckleImage();
$im->sharpenImage(0.5, 1);
//$im->reduceNoiseImage(0);
$im->setInterlaceScheme(Imagick::INTERLACE_PLANE);
$im->resizeImage($ancho, $alto, imagick::FILTER_LANCZOS, 1);
$im->writeImage($escalado);
$im->destroy();
}
$im = new Imagick($escalado);
$output = $im->getimageblob();
$outputtype = $im->getFormat();
$im->destroy();
header("Content-type: {$outputtype}");
header("Content-length: " . filesize($escalado));
echo $output;
}
示例2: image2data
/**
* Get image data from image object
* @param \Imagick $img
* @param string $type
* @return string mixed
*/
private static function image2data($img, $type = 'png')
{
$img->setImageFormat($type);
if ($img->getImageWidth() * $img->getImageHeight() > 40000) {
switch ($type) {
case 'png':
$img->setInterlaceScheme(\imagick::INTERLACE_PNG);
break;
case 'jpeg':
$img->setInterlaceScheme(\imagick::INTERLACE_JPEG);
break;
}
}
return $img->getImageBlob();
}
示例3: interlace
/**
* {@inheritdoc}
*/
public function interlace($scheme)
{
static $supportedInterlaceSchemes = array(ImageInterface::INTERLACE_NONE => \Imagick::INTERLACE_NO, ImageInterface::INTERLACE_LINE => \Imagick::INTERLACE_LINE, ImageInterface::INTERLACE_PLANE => \Imagick::INTERLACE_PLANE, ImageInterface::INTERLACE_PARTITION => \Imagick::INTERLACE_PARTITION);
if (!array_key_exists($scheme, $supportedInterlaceSchemes)) {
throw new InvalidArgumentException('Unsupported interlace type');
}
$this->imagick->setInterlaceScheme($supportedInterlaceSchemes[$scheme]);
return $this;
}
示例4: createThumbnail
function createThumbnail($filename, $thname, $width = 100, $height = 100, $cdn = null)
{
$filePath = 'pdfslice';
try {
$extension = substr($filename, strrpos($filename, '.') + 1 - strlen($filename));
$fallback_save_path = $filePath;
if ($extension == "svg") {
$im = new Imagick();
$svgdata = file_get_contents($filename);
$svgdata = svgScaleHack($svgdata, $width, $height);
//$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readImageBlob($svgdata);
$im->setImageFormat("jpg");
$im->resizeImage($width, $height, imagick::FILTER_LANCZOS, 1);
$raw_data = $im->getImageBlob();
is_null($cdn) ? file_put_contents($fallback_save_path . '/' . $thname, $im->getImageBlob()) : '';
} else {
if ($extension == "jpg") {
$im = new Imagick($filename);
$im->stripImage();
// Save as progressive JPEG
$im->setInterlaceScheme(Imagick::INTERLACE_PLANE);
$raw_data = $im->resizeImage($width, $height, imagick::FILTER_LANCZOS, 1);
// Set quality
// $im->setImageCompressionQuality(85);
is_null($cdn) ? $im->writeImage($fallback_save_path . '/' . $thname) : '';
}
}
if (!is_null($cdn)) {
$imageObject = $cdn->DataObject();
$imageObject->SetData($raw_data);
$imageObject->name = $thname;
$imageObject->content_type = 'image/jpg';
$imageObject->Create();
}
$im->clear();
$im->destroy();
return true;
} catch (Exception $e) {
return false;
}
}
示例5: transformImageMagickExt
/**
* Transform an image using the Imagick PHP extension
*
* @param File $image File associated with this thumbnail
* @param array $params Array with scaler params
*
* @return MediaTransformError Error object if error occurred, false (=no error) otherwise
*/
protected function transformImageMagickExt($image, $params)
{
global $wgSharpenReductionThreshold, $wgSharpenParameter, $wgMaxAnimatedGifArea, $wgJpegPixelFormat;
try {
$im = new Imagick();
$im->readImage($params['srcPath']);
if ($params['mimeType'] == 'image/jpeg') {
// Sharpening, see bug 6193
if (($params['physicalWidth'] + $params['physicalHeight']) / ($params['srcWidth'] + $params['srcHeight']) < $wgSharpenReductionThreshold) {
// Hack, since $wgSharpenParameter is written specifically for the command line convert
list($radius, $sigma) = explode('x', $wgSharpenParameter);
$im->sharpenImage($radius, $sigma);
}
$qualityVal = isset($params['quality']) ? (string) $params['quality'] : null;
$im->setCompressionQuality($qualityVal ?: 80);
if ($params['interlace']) {
$im->setInterlaceScheme(Imagick::INTERLACE_JPEG);
}
if ($wgJpegPixelFormat) {
$factors = $this->imageMagickSubsampling($wgJpegPixelFormat);
$im->setSamplingFactors($factors);
}
} elseif ($params['mimeType'] == 'image/png') {
$im->setCompressionQuality(95);
if ($params['interlace']) {
$im->setInterlaceScheme(Imagick::INTERLACE_PNG);
}
} elseif ($params['mimeType'] == 'image/gif') {
if ($this->getImageArea($image) > $wgMaxAnimatedGifArea) {
// Extract initial frame only; we're so big it'll
// be a total drag. :P
$im->setImageScene(0);
} elseif ($this->isAnimatedImage($image)) {
// Coalesce is needed to scale animated GIFs properly (bug 1017).
$im = $im->coalesceImages();
}
// GIF interlacing is only available since 6.3.4
$v = Imagick::getVersion();
preg_match('/ImageMagick ([0-9]+\\.[0-9]+\\.[0-9]+)/', $v['versionString'], $v);
if ($params['interlace'] && version_compare($v[1], '6.3.4') >= 0) {
$im->setInterlaceScheme(Imagick::INTERLACE_GIF);
}
}
$rotation = isset($params['disableRotation']) ? 0 : $this->getRotation($image);
list($width, $height) = $this->extractPreRotationDimensions($params, $rotation);
$im->setImageBackgroundColor(new ImagickPixel('white'));
// Call Imagick::thumbnailImage on each frame
foreach ($im as $i => $frame) {
if (!$frame->thumbnailImage($width, $height, false)) {
return $this->getMediaTransformError($params, "Error scaling frame {$i}");
}
}
$im->setImageDepth(8);
if ($rotation) {
if (!$im->rotateImage(new ImagickPixel('white'), 360 - $rotation)) {
return $this->getMediaTransformError($params, "Error rotating {$rotation} degrees");
}
}
if ($this->isAnimatedImage($image)) {
wfDebug(__METHOD__ . ": Writing animated thumbnail\n");
// This is broken somehow... can't find out how to fix it
$result = $im->writeImages($params['dstPath'], true);
} else {
$result = $im->writeImage($params['dstPath']);
}
if (!$result) {
return $this->getMediaTransformError($params, "Unable to write thumbnail to {$params['dstPath']}");
}
} catch (ImagickException $e) {
return $this->getMediaTransformError($params, $e->getMessage());
}
return false;
}
示例6: thumbnail_file_with_imagick
private function thumbnail_file_with_imagick($file_path, $save_as, $w = 0, $h = 0)
{
try {
$real_save_as = $save_as;
$save_as = tempnam(PERCH_RESFILEPATH, '_im_tmp_');
$Image = new Imagick($file_path . '[0]');
$Image->setImageFormat('jpg');
if ($Image->getImageHeight() <= $Image->getImageWidth()) {
$Image->thumbnailImage($w * $this->density, 0);
} else {
$Image->thumbnailImage(0, $w * $this->density);
}
// progressive jpg?
if ($this->progressive_jpeg) {
$Image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
}
$Image->writeImage($save_as);
copy($save_as, $real_save_as);
unlink($save_as);
$save_as = $real_save_as;
$out = array();
$out['w'] = (int) $Image->getImageWidth() / $this->density;
$out['h'] = (int) $Image->getImageHeight() / $this->density;
$out['file_path'] = $save_as;
$parts = explode(DIRECTORY_SEPARATOR, $save_as);
$out['file_name'] = array_pop($parts);
$out['web_path'] = str_replace(PERCH_RESFILEPATH . DIRECTORY_SEPARATOR, PERCH_RESPATH . '/', $save_as);
$out['density'] = $this->density;
$out['mime'] = 'image/' . $Image->getImageFormat();
$Image->destroy();
return $out;
} catch (Exception $e) {
PerchUtil::debug('Unable to create thumbnail', 'error');
PerchUtil::debug($e, 'error');
}
return false;
}
示例7: thumbnail_image
/**
* Efficiently resize the current image
*
* This is a WordPress specific implementation of Imagick::thumbnailImage(),
* which resizes an image to given dimensions and removes any associated profiles.
*
* @since 4.5.0
* @access protected
*
* @param int $dst_w The destination width.
* @param int $dst_h The destination height.
* @param string $filter_name Optional. The Imagick filter to use when resizing. Default 'FILTER_TRIANGLE'.
* @param bool $strip_meta Optional. Strip all profiles, excluding color profiles, from the image. Default true.
* @return bool|WP_Error
*/
protected function thumbnail_image($dst_w, $dst_h, $filter_name = 'FILTER_TRIANGLE', $strip_meta = true)
{
$allowed_filters = array('FILTER_POINT', 'FILTER_BOX', 'FILTER_TRIANGLE', 'FILTER_HERMITE', 'FILTER_HANNING', 'FILTER_HAMMING', 'FILTER_BLACKMAN', 'FILTER_GAUSSIAN', 'FILTER_QUADRATIC', 'FILTER_CUBIC', 'FILTER_CATROM', 'FILTER_MITCHELL', 'FILTER_LANCZOS', 'FILTER_BESSEL', 'FILTER_SINC');
/**
* Set the filter value if '$filter_name' name is in our whitelist and the related
* Imagick constant is defined or fall back to our default filter.
*/
if (in_array($filter_name, $allowed_filters) && defined('Imagick::' . $filter_name)) {
$filter = constant('Imagick::' . $filter_name);
} else {
$filter = defined('Imagick::FILTER_TRIANGLE') ? Imagick::FILTER_TRIANGLE : false;
}
/**
* Filters whether to strip metadata from images when they're resized.
*
* This filter only applies when resizing using the Imagick editor since GD
* always strips profiles by default.
*
* @since 4.5.0
*
* @param bool $strip_meta Whether to strip image metadata during resizing. Default true.
*/
if (apply_filters('image_strip_meta', $strip_meta)) {
$this->strip_meta();
// Fail silently if not supported.
}
try {
/*
* To be more efficient, resample large images to 5x the destination size before resizing
* whenever the output size is less that 1/3 of the original image size (1/3^2 ~= .111),
* unless we would be resampling to a scale smaller than 128x128.
*/
if (is_callable(array($this->image, 'sampleImage'))) {
$resize_ratio = $dst_w / $this->size['width'] * ($dst_h / $this->size['height']);
$sample_factor = 5;
if ($resize_ratio < 0.111 && ($dst_w * $sample_factor > 128 && $dst_h * $sample_factor > 128)) {
$this->image->sampleImage($dst_w * $sample_factor, $dst_h * $sample_factor);
}
}
/*
* Use resizeImage() when it's available and a valid filter value is set.
* Otherwise, fall back to the scaleImage() method for resizing, which
* results in better image quality over resizeImage() with default filter
* settings and retains backward compatibility with pre 4.5 functionality.
*/
if (is_callable(array($this->image, 'resizeImage')) && $filter) {
$this->image->setOption('filter:support', '2.0');
$this->image->resizeImage($dst_w, $dst_h, $filter, 1);
} else {
$this->image->scaleImage($dst_w, $dst_h);
}
// Set appropriate quality settings after resizing.
if ('image/jpeg' == $this->mime_type) {
if (is_callable(array($this->image, 'unsharpMaskImage'))) {
$this->image->unsharpMaskImage(0.25, 0.25, 8, 0.065);
}
$this->image->setOption('jpeg:fancy-upsampling', 'off');
}
if ('image/png' === $this->mime_type) {
$this->image->setOption('png:compression-filter', '5');
$this->image->setOption('png:compression-level', '9');
$this->image->setOption('png:compression-strategy', '1');
$this->image->setOption('png:exclude-chunk', 'all');
}
/*
* If alpha channel is not defined, set it opaque.
*
* Note that Imagick::getImageAlphaChannel() is only available if Imagick
* has been compiled against ImageMagick version 6.4.0 or newer.
*/
if (is_callable(array($this->image, 'getImageAlphaChannel')) && is_callable(array($this->image, 'setImageAlphaChannel')) && defined('Imagick::ALPHACHANNEL_UNDEFINED') && defined('Imagick::ALPHACHANNEL_OPAQUE')) {
if ($this->image->getImageAlphaChannel() === Imagick::ALPHACHANNEL_UNDEFINED) {
$this->image->setImageAlphaChannel(Imagick::ALPHACHANNEL_OPAQUE);
}
}
// Limit the bit depth of resized images to 8 bits per channel.
if (is_callable(array($this->image, 'getImageDepth')) && is_callable(array($this->image, 'setImageDepth'))) {
if (8 < $this->image->getImageDepth()) {
$this->image->setImageDepth(8);
}
}
if (is_callable(array($this->image, 'setInterlaceScheme')) && defined('Imagick::INTERLACE_NO')) {
$this->image->setInterlaceScheme(Imagick::INTERLACE_NO);
}
} catch (Exception $e) {
//.........這裏部分代碼省略.........
示例8: processFile
/**
* Set image file progressive settings
*/
protected function processFile()
{
$this->imagickObject->setInterlaceScheme($this->getInterlaceScheme());
}
示例9: getOption
/**
* Outputs an image resource as a given type
*
* @param Imagick $im
* @param string $type
* @param string $filename
* @param int $qual
* @return bool
*/
function zp_imageOutput($im, $type, $filename = NULL, $qual = 75)
{
$interlace = getOption('image_interlace');
$qual = max(min($qual, 100), 0);
$im->setImageFormat($type);
switch ($type) {
case 'gif':
$im->setImageCompression(Imagick::COMPRESSION_LZW);
$im->setImageCompressionQuality($qual);
if ($interlace) {
$im->setInterlaceScheme(Imagick::INTERLACE_GIF);
}
break;
case 'jpeg':
case 'jpg':
$im->setImageCompression(Imagick::COMPRESSION_JPEG);
$im->setImageCompressionQuality($qual);
if ($interlace) {
$im->setInterlaceScheme(Imagick::INTERLACE_JPEG);
}
break;
case 'png':
$im->setImageCompression(Imagick::COMPRESSION_ZIP);
$im->setImageCompressionQuality($qual);
if ($interlace) {
$im->setInterlaceScheme(Imagick::INTERLACE_PNG);
}
break;
}
$im->optimizeImageLayers();
if ($filename == NULL) {
header('Content-Type: image/' . $type);
return print $im->getImagesBlob();
}
return $im->writeImages(imgSrcURI($filename), true);
}
示例10: guess_image_type
/**
* Guess image mimetype from filename or from Content-Type header
*
* @arg $filename string Image filename
* @arg $fromcurl boolean Check Content-Type header from curl request
*/
function guess_image_type($filename, $fromcurl = false)
{
logger('Photo: guess_image_type: ' . $filename . ($fromcurl ? ' from curl headers' : ''), LOGGER_DEBUG);
$type = null;
if ($fromcurl) {
$a = get_app();
$headers = array();
$h = explode("\n", $a->get_curl_headers());
foreach ($h as $l) {
list($k, $v) = array_map("trim", explode(":", trim($l), 2));
$headers[$k] = $v;
}
if (array_key_exists('Content-Type', $headers)) {
$type = $headers['Content-Type'];
}
}
if (is_null($type)) {
// Guessing from extension? Isn't that... dangerous?
if (class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
/**
* Well, this not much better,
* but at least it comes from the data inside the image,
* we won't be tricked by a manipulated extension
*/
$image = new Imagick($filename);
$type = $image->getImageMimeType();
$image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
} else {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$types = Photo::supportedTypes();
$type = "image/jpeg";
foreach ($types as $m => $e) {
if ($ext == $e) {
$type = $m;
}
}
}
}
logger('Photo: guess_image_type: type=' . $type, LOGGER_DEBUG);
return $type;
}
示例11: resize
/**
* Resize
*
* @return bool
*/
public function resize()
{
try {
$resultMessage = array();
// Set filename
//@todo: check source
if (empty($this->filename)) {
$source = \explode('/', $this->source);
$this->setFileName($source[\count($source) - 1]);
}
// Define filename and extension
//@todo: check filename
$fileNameExtension = \substr($this->filename, \strrpos($this->filename, '.') + 1);
$fileName = \str_replace('.' . $fileNameExtension, '', $this->filename);
// Define retina size images
if ($this->retina === true) {
foreach ($this->type as $key => $imageType) {
$this->setType($key . self::RETINA_POSTFIX, $imageType['sizeWidth'] * 2, $imageType['sizeHeight'] * 2);
}
}
// Resize and save images
//@todo: check type
foreach ($this->type as $key => $imageType) {
$img = new \Imagick($this->source);
// Get exif and rotate the image
$exif = \exif_read_data($this->source, 'IFD0');
if (!empty($exif) && !empty($exif['Orientation'])) {
switch ($exif['Orientation']) {
case 8:
$img->rotateImage(new \ImagickPixel(), -90);
break;
case 3:
$img->rotateImage(new \ImagickPixel(), -180);
break;
case 6:
$img->rotateImage(new \ImagickPixel(), -270);
break;
default:
break;
}
}
// Get original size of the image
$imageWidth = $img->getImageWidth();
$imageHeight = $img->getImageHeight();
// Resize the image
if ($imageWidth > $imageHeight) {
$imageRotation = 'landscape';
} elseif ($imageWidth < $imageHeight) {
$imageRotation = 'portrait';
} else {
$imageRotation = 'square';
}
switch ($imageRotation) {
case 'landscape':
$img->resizeImage(\round($imageWidth / ($imageHeight / $imageType['sizeHeight'])), $imageType['sizeHeight'], \Imagick::FILTER_LANCZOS, 0.9, true);
break;
case 'portrait':
$img->resizeImage($imageType['sizeWidth'], \round($imageHeight / ($imageWidth / $imageType['sizeWidth'])), \Imagick::FILTER_LANCZOS, 0.9, true);
break;
case 'square':
$img->resizeImage($imageType['sizeWidth'], \round($imageHeight / ($imageWidth / $imageType['sizeWidth'])), \Imagick::FILTER_LANCZOS, 0.9, true);
break;
default:
break;
}
// Crop the image
$img->cropImage($imageType['sizeWidth'], $imageType['sizeHeight'], 0, 0);
// Sharpen image
$img->adaptiveSharpenImage(2, 1);
// Set progressive
if ($this->progressive === true) {
$img->setInterlaceScheme(\Imagick::INTERLACE_PLANE);
}
// Save
$outFileName = (empty($this->prefix) ? '' : $this->prefix . self::SEPARATOR) . $fileName . self::SEPARATOR . $key . '.' . $fileNameExtension;
@\unlink($this->target . '/' . $outFileName);
$img->writeImage($this->target . '/' . $outFileName);
$resultMessage[$key] = $outFileName;
}
// Save original image
if ($this->saveOriginal === true) {
// Save
$outFileName = (empty($this->prefix) ? '' : $this->prefix . self::SEPARATOR) . $fileName . '.' . $fileNameExtension;
@\unlink($this->target . '/' . $outFileName);
\copy($this->source, $this->target . '/' . $outFileName);
$resultMessage['original'] = $outFileName;
}
// Set status
$this->setStatus(self::STATUS_SUCCESS);
$this->setMessage(array('files' => $resultMessage));
return true;
} catch (\Exception $e) {
// Set status
$this->setStatus(self::STATUS_ERROR);
$this->setMessage($e->getMessage());
//.........這裏部分代碼省略.........
示例12: sharpen
/**
*
*/
function sharpen($path)
{
if (!class_exists('\\Imagick')) {
return;
}
$dimensions = @getimagesize($path);
if (!isset($dimensions[2]) || IMAGETYPE_JPEG != $dimensions[2]) {
return;
}
debug("sharpening {$path}", 6);
try {
$imagick = new \Imagick($path);
$imagick->unsharpMaskImage(0, 0.5, 1, 0);
$imagick->setImageFormat("jpg");
$imagick->setImageCompression(\Imagick::COMPRESSION_JPEG);
$imagick->setImageCompressionQuality(jpeg_quality());
$imagick->setInterlaceScheme(\Imagick::INTERLACE_PLANE);
// this is for watermarking
$imagick = \apply_filters("wp_resized2cache_imagick", $imagick, $path);
$imagick->writeImage($path);
$imagick->destroy();
} catch (Exception $e) {
debug('something went wrong with imagemagick: ', $e->getMessage(), 4);
return;
}
}
示例13: createThumbnail
/**
* @desc Create a thumbnail of the picture and save it
* @param $size The size requested
*/
private function createThumbnail($width, $height = false)
{
if (!$height) {
$height = $width;
}
$path = $this->_path . md5($this->_key) . '_' . $width . '.jpg';
$im = new Imagick();
$im->readImageBlob($this->_bin);
$geo = $im->getImageGeometry();
$im->cropThumbnailImage($width, $height);
if ($width > $geo['width']) {
$factor = floor($width / $geo['width']);
$im->blurImage($factor, 10);
}
$im->setImageCompressionQuality(85);
$im->setInterlaceScheme(Imagick::INTERLACE_PLANE);
$im->writeImage($path);
}
示例14: getOption
/**
* Outputs an image resource as a given type
*
* @internal Imagick::INTERLACE_[GIF|JPEG|PNG] require Imagick compiled against ImageMagick 6.3.4+
*
* @param Imagick $im
* @param string $type
* @param string $filename
* @param int $qual
* @throws ImagickException
* @return bool
*/
function zp_imageOutput($im, $type, $filename = NULL, $qual = 75)
{
global $_imagemagick_version, $_imagick_newer_interlace;
if (!isset($_imagick_newer_interlace)) {
$_imagick_newer_interlace = version_compare($_imagemagick_version['versionNumber'], '6.3.4', '>=');
}
$interlace = getOption('image_interlace');
$qual = max(min($qual, 100), 0);
$im->setImageFormat($type);
switch ($type) {
case 'gif':
$im->setCompression(Imagick::COMPRESSION_LZW);
$im->setCompressionQuality($qual);
if ($interlace) {
if ($_imagick_newer_interlace) {
$im->setInterlaceScheme(Imagick::INTERLACE_GIF);
} else {
$im->setInterlaceScheme(Imagick::INTERLACE_LINE);
}
}
break;
case 'jpeg':
case 'jpg':
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality($qual);
if ($interlace) {
if ($_imagick_newer_interlace) {
$im->setInterlaceScheme(Imagick::INTERLACE_JPEG);
} else {
$im->setInterlaceScheme(Imagick::INTERLACE_LINE);
}
}
break;
case 'png':
$im->setCompression(Imagick::COMPRESSION_ZIP);
$im->setCompressionQuality($qual);
if ($interlace) {
if ($_imagick_newer_interlace) {
$im->setInterlaceScheme(Imagick::INTERLACE_PNG);
} else {
$im->setInterlaceScheme(Imagick::INTERLACE_LINE);
}
}
break;
}
try {
$im->optimizeImageLayers();
} catch (ImagickException $e) {
if (DEBUG_IMAGE) {
debugLog('Caught ImagickException in zp_imageOutput(): ' . $e->getMessage());
}
}
if ($filename == NULL) {
header('Content-Type: image/' . $type);
return print $im->getImagesBlob();
}
return $im->writeImages($filename, true);
}
示例15: drawPolygon
/**
*
*
* @param
*
* @return void
*/
private function drawPolygon($event, $au_scalar, &$polyOffsetX, &$polyOffsetY, &$polygonURL, &$polyWidth, &$polyHeight)
{
$originX = null;
$originY = null;
$polygonURL = null;
$maxPixelScale = 0.60511022;
// arcseconds per pixel
$polyString = $event['hpc_boundcc'];
$polyString = str_replace(array('POLYGON', '(', ')'), '', $polyString);
foreach (explode(',', $polyString) as $xy) {
list($x_coord, $y_coord) = explode(' ', $xy);
$x[] = $x_coord * $au_scalar;
$y[] = -$y_coord * $au_scalar;
}
$originX = min($x);
$originY = min($y);
$polyOffsetX = $originX;
$polyOffsetY = $originY;
$width = 0;
$height = 0;
for ($i = 0; $i < count($x); $i++) {
$xCoord = ($x[$i] - $originX) / $maxPixelScale;
$yCoord = ($y[$i] - $originY) / $maxPixelScale;
$polyArray[] = array('x' => $xCoord, 'y' => $yCoord);
if ($xCoord > $width) {
$width = $xCoord;
}
if ($yCoord > $height) {
$height = $yCoord;
}
}
/* Create a new imagick object */
$im = new Imagick();
/* Create ImagickDraw object */
$draw = new ImagickDraw();
$strokeWidth = 4;
$draw->setStrokeLineJoin(Imagick::LINEJOIN_ROUND);
$draw->setStrokeColor('#00000088');
$draw->setStrokeWidth($strokeWidth);
$draw->setStrokeAntialias(true);
$draw->setFillColor('#' . $GLOBALS['HEK_COLORS'][$event['event_type']] . '66');
$draw->polygon($polyArray);
$polyWidth = $width + $strokeWidth;
$polyHeight = $height + $strokeWidth;
/* Create a new canvas object and a transparent image */
$canvas = new Imagick();
$canvas->newImage($polyWidth, $polyHeight, 'none');
/* Draw the ImagickDraw on to the canvas */
$canvas->drawImage($draw);
/* Set the format to PNG */
$canvas->setImageFormat('png');
$canvas->setInterlaceScheme(Imagick::INTERLACE_PNG);
/* Output the image */
$dateArray = date_parse($event['event_starttime']);
$cache_base_dir = HV_CACHE_DIR . '/events/' . $dateArray['year'] . '/' . str_pad($dateArray['month'], 2, '0', STR_PAD_LEFT) . '/' . str_pad($dateArray['day'], 2, '0', STR_PAD_LEFT);
// Check for existence of cache sub-directory
if (!@file_exists($cache_base_dir)) {
@mkdir($cache_base_dir, 0777, true);
}
$cache_file = rawurlencode($event['kb_archivid']) . '.png';
$cache_file_path = $cache_base_dir . '/' . $cache_file;
$polygonURL = str_replace(HV_CACHE_DIR, 'cache', $cache_base_dir) . '/' . rawurlencode($cache_file);
$fp = @fopen($cache_file_path, 'wb');
if ($fp !== false) {
@fwrite($fp, $canvas);
@fclose($fp);
}
}