本文整理匯總了PHP中Imagick::scaleImage方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::scaleImage方法的具體用法?PHP Imagick::scaleImage怎麽用?PHP Imagick::scaleImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::scaleImage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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();
}
示例2: index
public function index()
{
$ps = array();
$user = $this->session->all_userdata();
if (isset($_POST['submit']) && isset($user) && isset($user['users_id']) && isset($_FILES['uploaded_image']['tmp_name'])) {
$imageFile = time() . '.' . end(explode(".", $_FILES['uploaded_image']['name']));
$photoData = $_POST['photo'];
$image = new Imagick($_FILES['uploaded_image']['tmp_name']);
$height = $image->getImageHeight();
$width = $image->getImageWidth();
if ($width > 800 || $height > 800) {
if ($height < $width) {
$image->scaleImage(800, 0);
} else {
$image->scaleImage(0, 600);
}
}
$image->writeImage('./storage/photos/b/' . $imageFile);
$image->cropThumbnailImage(100, 100);
$image->writeImage('./storage/thumbs/' . $imageFile);
$ps['photo_b'] = '/storage/photos/b/' . $imageFile;
$ps['thumb'] = '/storage/thumbs/' . $imageFile;
$data = array('iname' => $photoData['iname'] ? $photoData['iname'] : 'noname', 'idesc' => $photoData['idesc'] ? $photoData['idesc'] : '', 'path' => '/storage/photos/', 'file' => $imageFile, 'thumb' => $ps['thumb'], 'add_date' => time(), 'allow_comments' => isset($photoData['allow_comments']) ? 1 : 0, 'users_id' => $user['users_id']);
$this->db->insert('photos', $data);
$photos_id = $this->db->insert_id();
$this->load->model('m_users');
$this->load->model('m_logs');
$this->m_users->update(array('num_photos' => $user['num_photos'] + 1), $user['users_id']);
$this->m_logs->add(array('users_id' => $user['users_id'], 'action' => 1, 'object_type' => 2, 'object_id' => $photos_id));
}
$ps['_activeMenu'] = 'upload';
$this->tpl->view('frontend/upload/', $ps);
}
示例3: _resize
/**
* Resize the image.
* @param integer $width
* @param integer $height
*/
protected function _resize($width, $height)
{
if ($this->im->scaleImage($width, $height)) {
$this->width = $this->im->getImageWidth();
$this->height = $this->im->getImageHeight();
}
}
示例4: resize
/**
* @see AbstractImage::resize
*/
public function resize($iWidth = null, $iHeight = null)
{
//If null given, compute a valid size
if (is_null($iWidth)) {
$iWidth = $this->width * $iHeight / $this->height;
}
if (is_null($iHeight)) {
$iHeight = $this->height * $iWidth / $this->width;
}
$this->resource->scaleImage($iWidth, $iHeight);
$this->width = $iWidth;
$this->height = $iHeight;
}
示例5: crop
/**
* Crops Image.
*
* @since 3.5.0
* @access public
*
* @param int $src_x The start x position to crop from.
* @param int $src_y The start y position to crop from.
* @param int $src_w The width to crop.
* @param int $src_h The height to crop.
* @param int $dst_w Optional. The destination width.
* @param int $dst_h Optional. The destination height.
* @param bool $src_abs Optional. If the source crop points are absolute.
* @return bool|WP_Error
*/
public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false)
{
if ($src_abs) {
$src_w -= $src_x;
$src_h -= $src_y;
}
try {
$this->image->cropImage($src_w, $src_h, $src_x, $src_y);
$this->image->setImagePage($src_w, $src_h, 0, 0);
if ($dst_w || $dst_h) {
// If destination width/height isn't specified, use same as
// width/height from source.
if (!$dst_w) {
$dst_w = $src_w;
}
if (!$dst_h) {
$dst_h = $src_h;
}
$this->image->scaleImage($dst_w, $dst_h);
return $this->update_size();
}
} catch (Exception $e) {
return new WP_Error('image_crop_error', $e->getMessage());
}
return $this->update_size();
}
示例6: image
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $format = "png", $quality = 85, $filename = FALSE, $save = TRUE, $print = false)
{
$imgH = count($frame);
$imgW = strlen($frame[0]);
$col[0] = new \ImagickPixel("white");
$col[1] = new \ImagickPixel("black");
$image = new \Imagick();
$image->newImage($imgW, $imgH, $col[0]);
$image->setCompressionQuality($quality);
$image->setImageFormat($format);
$draw = new \ImagickDraw();
$draw->setFillColor($col[1]);
for ($y = 0; $y < $imgH; $y++) {
for ($x = 0; $x < $imgW; $x++) {
if ($frame[$y][$x] == '1') {
$draw->point($x, $y);
}
}
}
$image->drawImage($draw);
$image->borderImage($col[0], $outerFrame, $outerFrame);
$image->scaleImage(($imgW + 2 * $outerFrame) * $pixelPerPoint, 0);
if ($save) {
if ($filename === false) {
throw new Exception("QR Code filename can't be empty");
}
$image->writeImages($filename, true);
}
if ($print) {
Header("Content-type: image/" . $format);
echo $image;
}
}
示例7: resize
/**
* @param int $width
* @param int $height
*
* @return static
*/
public function resize($width, $height)
{
$this->_image->scaleImage($width, $height);
$this->_width = $this->_image->getImageWidth();
$this->_height = $this->_image->getImageHeight();
return $this;
}
示例8: getAction
public function getAction($systemIdentifier, Request $request)
{
$width = $request->get('width');
$height = $request->get('height');
$system = $this->getDoctrine()->getRepository('KoalamonIncidentDashboardBundle:System')->findOneBy(['identifier' => $systemIdentifier, 'project' => $this->getProject()]);
$webDir = $this->container->getParameter('assetic.write_to');
if ($system->getImage() == "") {
$imageName = $webDir . self::DEFAULT_IMAGE;
} else {
$imageName = $webDir . ScreenshotCommand::IMAGE_DIR . DIRECTORY_SEPARATOR . $system->getImage();
}
$image = new \Imagick($imageName);
if ($height || $width) {
if (!$height) {
$ratio = $width / $image->getImageWidth();
$height = $image->getImageHeight() * $ratio;
}
if (!$width) {
$ratio = $height / $image->getImageHeight();
$width = $image->getImageWidth() * $ratio;
}
$image->scaleImage($width, $height, true);
}
$headers = array('Content-Type' => 'image/png', 'Content-Disposition' => 'inline; filename="' . $imageName . '"');
return new Response($image->getImageBlob(), 200, $headers);
}
示例9: mkbilder
function mkbilder($typ)
{
$this->err->write('mkbilder', $typ);
$org = new Imagick();
if (!$org->readImage("/tmp/tmp.file_org")) {
return false;
}
$big = new Imagick();
$big->newImage($this->bigwidth, $this->bigheight, new ImagickPixel('white'));
$big->setImageFormat($typ);
//$big->setImageColorspace($org->getImageColorspace() );
$big->setImageType(imagick::IMGTYPE_TRUECOLOR);
$org->scaleImage($this->bigwidth, $this->bigheight, true);
$d = $org->getImageGeometry();
$xoff = ($this->bigwidth - $d['width']) / 2;
$big->compositeImage($org, imagick::COMPOSITE_DEFAULT, $xoff, 0);
$rc = $big->writeImage("/tmp/tmp.file_org");
$big->clear();
$big->destroy();
$small = new Imagick();
$small->newImage($this->smallwidth, $this->smallheight, new ImagickPixel('white'));
$small->setImageFormat($typ);
//$small->setImageColorspace($org->getImageColorspace() );
$small->setImageType(imagick::IMGTYPE_TRUECOLOR);
$org->scaleImage($this->smallwidth, $this->smallheight, true);
$d = $org->getImageGeometry();
$xoff = ($this->smallwidth - $d['width']) / 2;
$small->compositeImage($org, imagick::ALIGN_CENTER, $xoff, 0);
$rc = $small->writeImage("/tmp/tmp.file_small");
$small->clear();
$small->destroy();
$org->clear();
$org->destroy();
return true;
}
示例10: save
public function save()
{
$success = parent::save();
if ($success && isset($this->tempFile)) {
$extension = $this->getExtension();
// save original
$original = $this->name . "." . $extension;
$path = $this->getPath(null, true);
$this->logger->log("moving " . $this->tempFile["tmp_name"] . " to " . $path);
$success = move_uploaded_file($this->tempFile["tmp_name"], $path);
if ($success && $this->isImage()) {
$thumbs = array(array('width' => 200, 'suffix' => 'small'), array('width' => 500, 'suffix' => 'med'));
foreach ($thumbs as $thumb) {
$thumb_path = $this->getPath($thumb['suffix'], true);
$this->logger->log("thumbnailing " . $this->tempFile["tmp_name"] . " to " . $thumb_path);
$image = new Imagick($path);
$image->scaleImage($thumb['width'], 0);
$image->writeImage($thumb_path);
$image->destroy();
}
} else {
if (!$success) {
$this->errorMessage = "Oops! We had trouble moving the file. Please try again later.";
$success = false;
}
}
} else {
$this->status = "Sorry, there was an error with the file: " . $this->tempFile["error"];
$success = false;
}
return $success;
}
示例11: pixelate
/**
* {@inheritdoc}
*/
public function pixelate($pixelSize = 10)
{
$width = $this->image->getImageWidth();
$height = $this->image->getImageHeight();
$this->image->scaleImage((int) ($width / $pixelSize), (int) ($height / $pixelSize));
$this->image->scaleImage($width, $height);
}
示例12: programmatically_create_post
function programmatically_create_post()
{
$url = 'http://widgets.pinterest.com/v3/pidgets/boards/bradleyblose/my-stuff/pins/';
$json_O = json_decode(file_get_contents($url), true);
$id = $json_O['data']['pins'][0]['id'];
$titlelink = 'https://www.pinterest.com/pin/' . $id . '/';
$title = get_title($titlelink);
var_dump($title);
$original = $json_O['data']['pins'][0]['images']['237x']['url'];
$image_url = preg_replace('/237x/', '736x', $original);
$description = $json_O['data']['pins'][0]['description'];
// Initialize the page ID to -1. This indicates no action has been taken.
$post_id = -1;
// Setup the author, slug, and title for the post
$author_id = 1;
$mytitle = get_page_by_title($title, OBJECT, 'post');
var_dump($mytitle);
// If the page doesn't already exist, then create it
if (NULL == get_page_by_title($title, OBJECT, 'post')) {
// Set the post ID so that we know the post was created successfully
$post_id = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $author_id, 'post_name' => $title, 'post_title' => $title, 'post_content' => $description, 'post_status' => 'publish', 'post_type' => 'post'));
//upload featured image
$upload_dir = wp_upload_dir();
$image_data = file_get_contents($image_url);
$filename = basename($image_url);
if (wp_mkdir_p($upload_dir['path'])) {
$file = $upload_dir['path'] . '/' . $filename;
$path = $upload_dir['path'] . '/';
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
$path = $upload_dir['basedir'] . '/';
}
file_put_contents($file, $image_data);
//edit featured image to correct specs to fit theme
$pngfilename = $filename . '.png';
$targetThumb = $path . '/' . $pngfilename;
$img = new Imagick($file);
$img->scaleImage(250, 250, true);
$img->setImageBackgroundColor('None');
$w = $img->getImageWidth();
$h = $img->getImageHeight();
$img->extentImage(250, 250, ($w - 250) / 2, ($h - 250) / 2);
$img->writeImage($targetThumb);
unlink($file);
//Attach featured image
$wp_filetype = wp_check_filetype($pngfilename, null);
$attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($pngfilename), 'post_content' => '', 'post_status' => 'inherit');
$attach_id = wp_insert_attachment($attachment, $targetThumb, $post_id);
require_once ABSPATH . 'wp-admin/includes/image.php';
$attach_data = wp_generate_attachment_metadata($attach_id, $targetThumb);
wp_update_attachment_metadata($attach_id, $attach_data);
set_post_thumbnail($post_id, $attach_id);
// Otherwise, we'll stop
} else {
// Arbitrarily use -2 to indicate that the page with the title already exists
$post_id = -2;
}
// end if
}
示例13: scale
public function scale($scale)
{
$width = ceil($this->width * $scale);
$height = ceil($this->height * $scale);
$this->image->scaleImage($width, $height, true);
$this->updateSize($width, $height);
return $this;
}
示例14: scale
/**
* {@inheritdoc}
*/
public function scale(BoxInterface $size)
{
try {
$this->imagick->scaleImage($size->getWidth(), $size->getHeight());
} catch (\ImagickException $e) {
throw new RuntimeException('Scale operation failed', $e->getCode(), $e);
}
return $this;
}
示例15: analyzeImage
/**
* @param \Imagick $imagick
* @param int $graphWidth
* @param int $graphHeight
*/
public static function analyzeImage(\Imagick $imagick, $graphWidth = 255, $graphHeight = 127)
{
$sampleHeight = 20;
$border = 2;
$imagick->transposeImage();
$imagick->scaleImage($graphWidth, $sampleHeight);
$imageIterator = new \ImagickPixelIterator($imagick);
$luminosityArray = [];
foreach ($imageIterator as $row => $pixels) {
/* Loop through pixel rows */
foreach ($pixels as $column => $pixel) {
/* Loop through the pixels in the row (columns) */
/** @var $pixel \ImagickPixel */
if (false) {
$color = $pixel->getColor();
$luminosityArray[] = $color['r'];
} else {
$hsl = $pixel->getHSL();
$luminosityArray[] = $hsl['luminosity'];
}
}
/* Sync the iterator, this is important to do on each iteration */
$imageIterator->syncIterator();
break;
}
$draw = new \ImagickDraw();
$strokeColor = new \ImagickPixel('red');
$fillColor = new \ImagickPixel('red');
$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);
$draw->setStrokeWidth(0);
$draw->setFontSize(72);
$draw->setStrokeAntiAlias(true);
$previous = false;
$x = 0;
foreach ($luminosityArray as $luminosity) {
$pos = $graphHeight - 1 - $luminosity * ($graphHeight - 1);
if ($previous !== false) {
/** @var $previous int */
//printf ( "%d, %d, %d, %d <br/>\n" , $x - 1, $previous, $x, $pos);
$draw->line($x - 1, $previous, $x, $pos);
}
$x += 1;
$previous = $pos;
}
$plot = new \Imagick();
$plot->newImage($graphWidth, $graphHeight, 'white');
$plot->drawImage($draw);
$outputImage = new \Imagick();
$outputImage->newImage($graphWidth, $graphHeight + $sampleHeight, 'white');
$outputImage->compositeimage($plot, \Imagick::COMPOSITE_ATOP, 0, 0);
$outputImage->compositeimage($imagick, \Imagick::COMPOSITE_ATOP, 0, $graphHeight);
$outputImage->borderimage('black', $border, $border);
$outputImage->setImageFormat("png");
App::cachingHeader("Content-Type: image/png");
echo $outputImage;
}