本文整理匯總了PHP中Imagick::setImageFormat方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::setImageFormat方法的具體用法?PHP Imagick::setImageFormat怎麽用?PHP Imagick::setImageFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::setImageFormat方法的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: pdfAction
public function pdfAction()
{
$model = $this->_processSvg();
$scale = $this->getRequest()->getPost('print_scale');
$model->addWhiteFontForPDF();
$data = $model->normalizeSvgData();
if ($model->getAdditionalData('order_increment_id')) {
$filename = 'Order_' . $model->getAdditionalData('order_increment_id') . '_Image.pdf';
} else {
$filename = 'Customer_Product_Image.pdf';
}
$this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Content-type', 'application/pdf', true)->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"', true);
$this->getResponse()->clearBody();
//$this->getResponse()->setBody(str_replace('xlink:','',$data));
$imagick = new Imagick();
$imagick->readImageBlob($data);
if ($scale != 1 && $scale <= 15) {
$imagick->scaleImage($scale * $imagick->getImageWidth(), $scale * $imagick->getImageHeight());
}
$imagick->setImageFormat("pdf");
/*$imagick->writeImage(MAGENTO_ROOT.'/media/us-map.pdf');scaleImage */
$this->getResponse()->setBody($imagick);
$imagick->clear();
$imagick->destroy();
}
示例3: save
/**
* 保存圖像
* @param string $imgname 圖像保存名稱
* @param string $type 圖像類型
* @param boolean $interlace 是否對JPEG類型圖像設置隔行掃描
* @throws \Exception
*/
public function save($imgname, $type = NULL, $interlace = true)
{
if (empty($this->img)) {
throw new \Exception(_('No image resources can be saved'));
}
//設置圖片類型
if (is_null($type)) {
$type = $this->info['type'];
} else {
$type = strtolower($type);
$this->img->setImageFormat($type);
}
//JPEG圖像設置隔行掃描
if ('jpeg' == $type || 'jpg' == $type) {
$this->img->setImageInterlaceScheme(1);
}
//去除圖像配置信息
$this->img->stripImage();
//保存圖像
$imgname = realpath(dirname($imgname)) . '/' . basename($imgname);
//強製絕對路徑
if ('gif' == $type) {
$this->img->writeImages($imgname, true);
} else {
$this->img->writeImage($imgname);
}
}
示例4: save
function save($file_name = null, $quality = null)
{
$type = $this->out_type;
if (!$type) {
$type = $this->img_type;
}
if (!self::supportSaveType($type)) {
throw new lmbImageTypeNotSupportedException($type);
}
$this->img->setImageFormat($type);
$this->img->setImageFilename($file_name);
if (!is_null($quality) && strtolower($type) == 'jpeg') {
if (method_exists($this->img, 'setImageCompression')) {
$this->img->setImageCompression(imagick::COMPRESSION_JPEG);
$this->img->setImageCompressionQuality($quality);
} else {
$this->img->setCompression(imagick::COMPRESSION_JPEG);
$this->img->setCompressionQuality($quality);
}
}
if (!$this->img->writeImage($file_name)) {
throw new lmbImageSaveFailedException($file_name);
}
$this->destroyImage();
}
示例5: save
/**
* @param $path
*/
public function save($path, $format = null, $quality = null)
{
if (!$format) {
$format = "png";
}
$this->resource->stripimage();
$this->resource->setImageFormat($format);
if ($quality) {
$this->resource->setCompressionQuality((int) $quality);
$this->resource->setImageCompressionQuality((int) $quality);
}
$this->resource->writeImage($path);
return $this;
}
示例6: assignMimeType
public function assignMimeType(Imagick $target)
{
if ($this->mimeType == 'image/jpeg') {
$target->setImageFormat('jpg');
} else {
if ($this->mimeType == 'image/gif') {
$target->setImageFormat('gif');
} else {
if ($this->mimeType == 'image/png') {
$target->setImageFormat('png');
}
}
}
}
示例7: apply
/**
* {@inheritDoc}
*/
public function apply($absolutePath)
{
$info = pathinfo($absolutePath);
if (isset($info['extension']) && false !== strpos(strtolower($info['extension']), 'pdf')) {
// If it doesn't exists, extract the first page of the PDF
if (!file_exists("{$absolutePath}.png")) {
$this->imagick->readImage($absolutePath . '[0]');
$this->imagick->setImageFormat('png');
$this->imagick->writeImage("{$absolutePath}.png");
$this->imagick->clear();
}
$absolutePath .= '.png';
}
return $absolutePath;
}
示例8: _save_function
protected function _save_function($extension, &$quality)
{
switch (strtolower($extension)) {
case 'jpg':
case 'jpeg':
$type = IMAGETYPE_JPEG;
if ($this->type == "png" || $this->type == "gif") {
$this->im->borderImage(new ImagickPixel("white"), 1, 1);
}
$this->im->setImageFormat('jpeg');
break;
case 'gif':
$type = IMAGETYPE_GIF;
$this->im->setImageFormat('gif');
break;
case 'png':
$type = IMAGETYPE_PNG;
$this->im->setImageFormat('png');
break;
default:
throw new waException(_ws(sprintf('Installed ImageMagick does not support %s images', $extension)));
break;
}
$quality = $quality - 5;
return $type;
}
示例9: convert
/**
* Tries to converts the <b>$input</b> image into the <b>$output</b> format.
*
* @param string $input The input file.
* @param string $output The output file.
* @return void
*/
public static function convert($input, $output)
{
$inputType = strtolower(pathinfo($input, PATHINFO_EXTENSION));
$outputType = strtolower(pathinfo($output, PATHINFO_EXTENSION));
// Check for output file without extension and reuse input type
if ($outputType === '') {
$outputType = $inputType;
$output .= ".{$outputType}";
}
if ($inputType === 'svg') {
self::prepareSvg($input);
}
if ($inputType === $outputType) {
file_put_contents($output, file_get_contents($input));
} elseif (extension_loaded('imagick') === true) {
$imagick = new \Imagick($input);
$imagick->setImageFormat($outputType);
$imagick->writeImage($output);
// The following code is not testable when imagick is installed
// @codeCoverageIgnoreStart
} elseif (self::hasImagickConvert() === true) {
$input = escapeshellarg($input);
$output = escapeshellarg($output);
system("convert {$input} {$output}");
} else {
$fallback = substr($output, 0, -strlen($outputType)) . $inputType;
echo "WARNING: Cannot generate image of type '{$outputType}'. This", " feature needs either the\n pecl/imagick extension or", " the ImageMagick cli tool 'convert'.\n\n", "Writing alternative image:\n{$fallback}\n\n";
file_put_contents($fallback, file_get_contents($input));
}
// @codeCoverageIgnoreEnd
}
示例10: alfath_svg_compiler
function alfath_svg_compiler($options)
{
global $wp_filesystem;
if (!class_exists('Imagick')) {
return new WP_Error('class_not_exist', 'Your server not support imagemagick');
}
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel('transparent'));
if (empty($wp_filesystem)) {
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();
}
$file = get_template_directory() . '/assets/img/nav.svg';
$target = get_template_directory() . '/assets/img/nav-bg.png';
if ($wp_filesystem->exists($file)) {
//check for existence
$svg = $wp_filesystem->get_contents($file);
if (!$svg) {
return new WP_Error('reading_error', 'Error when reading file');
}
//return error object
$svg = preg_replace('/fill="#([0-9a-f]{6})"/', 'fill="' . $options['secondary-color'] . '"', $svg);
$im->readImageBlob($svg);
$im->setImageFormat("png24");
$im->writeImage($target);
$im->clear();
$im->destroy();
} else {
return new WP_Error('not_found', 'File not found');
}
}
示例11: create_thumb
function create_thumb($source_file, $thumb_file, $edge = THUMBNAIL_CROP_EDGE, &$src_w = NULL, &$src_h = NULL)
{
$composite_img = new Imagick($source_file);
$blank_img = new Imagick();
$src_w = $composite_img->getImageWidth();
$src_h = $composite_img->getImageHeight();
if ($src_h > $edge && $src_w > $edge) {
$composite_img->cropThumbnailImage($edge, $edge);
$composite_img->setImageFormat('jpeg');
$composite_img->writeImage($thumb_file);
$composite_img->clear();
$blank_img = $composite_img;
} else {
$blank_img->newImage($edge, $edge, new ImagickPixel('#DEF'), "jpg");
if ($src_w > $src_h) {
$crop_x = $src_w / 2 - $edge / 2;
$crop_y = 0;
$offset_x = 0;
$offset_y = $edge / 2 - $src_h / 2;
} else {
$crop_x = 0;
$crop_y = $src_h / 2 - $edge / 2;
$offset_x = $edge / 2 - $src_w / 2;
$offset_y = 0;
}
$composite_img->cropImage($edge, $edge, $crop_x, $crop_y);
$blank_img->compositeImage($composite_img, Imagick::COMPOSITE_OVER, $offset_x, $offset_y);
$blank_img->setImageFormat('jpeg');
$blank_img->writeImage($thumb_file);
$blank_img->clear();
}
return $blank_img;
}
示例12: getThumbnail
/**
* {@inheritDoc}
*/
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
try {
$svg = new \Imagick();
$svg->setBackgroundColor(new \ImagickPixel('transparent'));
$content = stream_get_contents($fileview->fopen($path, 'r'));
if (substr($content, 0, 5) !== '<?xml') {
$content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
}
// Do not parse SVG files with references
if (stripos($content, 'xlink:href') !== false) {
return false;
}
$svg->readImageBlob($content);
$svg->setImageFormat('png32');
} catch (\Exception $e) {
\OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::ERROR);
return false;
}
//new image object
$image = new \OC_Image();
$image->loadFromData($svg);
//check if image object is valid
if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
return $image;
}
return false;
}
示例13: display
/**
* Displays image without saving and lose changes
*
* This method adds the Content-type HTTP header
*
* @param string type (JPG,PNG...);
* @param int quality 75
*
* @return bool|PEAR_Error TRUE or a PEAR_Error object on error
* @access public
*/
function display($type = '', $quality = null)
{
$options = is_array($quality) ? $quality : array();
if (is_numeric($quality)) {
$options['quality'] = $quality;
}
$quality = $this->_getOption('quality', $options, 75);
$this->imagick->setImageCompression($quality);
if ($type && strcasecmp($type, $this->type)) {
try {
$this->imagick->setImageFormat($type);
} catch (ImagickException $e) {
return $this->raiseError('Could not save image to file (conversion failed).', IMAGE_TRANSFORM_ERROR_FAILED);
}
}
try {
$image = $this->imagick->getImageBlob();
} catch (ImagickException $e) {
return $this->raiseError('Could not display image.', IMAGE_TRANSFORM_ERROR_IO);
}
header('Content-type: ' . $this->getMimeType($type));
echo $image;
$this->free();
return true;
}
示例14: prepareOutput
/**
* @param array $options
* @param string $path
*/
private function prepareOutput(array $options, $path = null)
{
if (isset($options['format'])) {
$this->imagick->setImageFormat($options['format']);
}
if (isset($options['animated']) && true === $options['animated']) {
$format = isset($options['format']) ? $options['format'] : 'gif';
$delay = isset($options['animated.delay']) ? $options['animated.delay'] : null;
$loops = 0;
if (isset($options['animated.loops'])) {
$loops = $options['animated.loops'];
} else {
// Calculating animated GIF iterations is a crap-shoot: https://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=23276
// Looks like it started working around 6.8.8-3: http://git.imagemagick.org/repos/ImageMagick/blob/a01518e08c840577cabd7d3ff291a9ba735f7276/ChangeLog#L914-916
$versionInfo = $this->imagick->getVersion();
if (isset($versionInfo['versionString'])) {
preg_match('/ImageMagick ([0-9]+\\.[0-9]+\\.[0-9]+-[0-9])/', $versionInfo['versionString'], $versionInfo);
if (isset($versionInfo[1])) {
if (version_compare($versionInfo[1], '6.8.8-3', '>=')) {
$loops = $this->imagick->getImageIterations();
}
}
}
}
$options['flatten'] = false;
$this->layers->animate($format, $delay, $loops);
} else {
$this->layers->merge();
}
$this->applyImageOptions($this->imagick, $options, $path);
// flatten only if image has multiple layers
if ((!isset($options['flatten']) || $options['flatten'] === true) && count($this->layers) > 1) {
$this->flatten();
}
}
示例15: Imagick
function page_testfonts()
{
//load background
$im = new Imagick();
$im->newimage(800, 10000, 'lightgray');
$y = 10;
$i = 1;
foreach ($im->queryFonts() as $font) {
$insert_image = new Imagick();
$insert_image->newImage(600, 30, 'whitesmoke');
$insert_image->setImageFormat("png");
$draw = new ImagickDraw();
$draw->setFont($font);
$draw->setFontSize(25);
$draw->setFillColor(new ImagickPixel('black'));
$draw->setgravity(imagick::GRAVITY_NORTH);
$insert_image->annotateImage($draw, 0, 0, 0, $i . '.' . $font);
$im->compositeImage($insert_image, $insert_image->getImageCompose(), 100, $y);
$y += 30;
$i++;
}
$im->setImageFormat('jpg');
header('Content-Type: image/jpg');
echo $im;
}