本文整理匯總了PHP中Imagick::scaleimage方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::scaleimage方法的具體用法?PHP Imagick::scaleimage怎麽用?PHP Imagick::scaleimage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::scaleimage方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
// 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;
}
示例2: resizeImage
function resizeImage($imagePath, $width, $height, $filterType, $blur, $bestFit, $cropZoom)
{
//The blur factor where > 1 is blurry, < 1 is sharp.
$imagick = new \Imagick(realpath($imagePath));
$imagick->resizeImage($width, $height, $filterType, $blur, $bestFit);
$cropWidth = $imagick->getImageWidth();
$cropHeight = $imagick->getImageHeight();
if ($cropZoom) {
$newWidth = $cropWidth / 2;
$newHeight = $cropHeight / 2;
$imagick->cropimage($newWidth, $newHeight, ($cropWidth - $newWidth) / 2, ($cropHeight - $newHeight) / 2);
$imagick->scaleimage($imagick->getImageWidth() * 4, $imagick->getImageHeight() * 4);
}
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
}
示例3: resize
/**
* Resizes an image image
* @return boolean
*/
public function resize()
{
try {
// Create new Image object //
$im = new Imagick($this->image->get('image_path'));
// Resize the image //
$im->scaleimage($this->image->get('height'), $this->image->get('width'));
// Grab the output from writing the image to disk //
$return = $im->writeimage($this->image->get('resized_path'));
// Clean up memory //
$im->clear();
$im->destroy();
// $return only returns true if image is written //
return $return ? true : false;
} catch (Exception $e) {
$this->log->exceptionLog($e, __METHOD__);
}
}
示例4: beforeSave
public function beforeSave($options = array())
{
Configure::write('debug', 2);
parent::beforeSave($options);
if (isset($this->data[$this->alias]['cash_by_promo'])) {
if ($this->data[$this->alias]['cash_by_promo'] > 120) {
unset($this->data[$this->alias]['cash_by_promo']);
//HackPreventions
}
}
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['v_code'] = $this->data[$this->alias]['password'];
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
if (isset($this->data[$this->alias]['image'])) {
App::uses("HtmlHelper", "View/Helper");
$html = new HtmlHelper(new View());
if (isset($this->data[$this->alias]['image']['name'])) {
if (isset($this->data[$this->alias]['image']['size'])) {
if (isset($this->data[$this->alias]['id'])) {
$fx = $this->find("first", array("contain" => false, "conditions" => array("Customer.id" => $this->data[$this->alias]['id'])));
$fn = ltrim($fx[$this->alias]['image'], "https://www.pickmeals.com/");
@unlink($fn);
}
$ext = pathinfo($this->data[$this->alias]['image']['name'], PATHINFO_EXTENSION);
$image_name = date('YmdHis') . rand(1, 999) . "." . $ext;
$path = $this->data[$this->alias]['image']['tmp_name'];
$this->data[$this->alias]['image'] = $html->url("/files/profile_image/" . $image_name, true);
$destination = "files/profile_image/" . $image_name;
move_uploaded_file($path, $destination);
$im = new Imagick($destination);
$im->scaleimage(800, 0);
$im->writeimage($destination);
$im->destroy();
}
}
}
return TRUE;
}
示例5: createBowl
function createBowl($dishUrl = null, $w = 140, $h = 0)
{
$du = explode("/", $dishUrl);
$du = explode(".", $du[count($du) - 1]);
$uri = $du[count($du) - 2];
$bowl = new Imagick("img/bowl.png");
$mask = new Imagick("img/mask.png");
$dish = new Imagick($dishUrl);
$dish->scaleimage($bowl->getimagewidth(), $bowl->getimageheight());
// Set As per bowl image
$dish->compositeimage(new Imagick("img/mask.png"), \Imagick::COMPOSITE_COPYOPACITY, 0, 0, Imagick::CHANNEL_ALPHA);
$dish->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$bowl->compositeimage($dish, \Imagick::COMPOSITE_ATOP, 0, 0, Imagick::CHANNEL_ALPHA);
$bowl->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$bowl->setimageformat("jpg");
$bowl->setImageFileName($url = "gen/" . $uri . ".jpg");
// $bowl->setinterlacescheme(\Imagick::INTERLACE_PNG);
$bowl->scaleimage($w, $h);
$bowl->writeimage();
$bowl->destroy();
return $url;
}
示例6: watermark
/**
* @param $watermarkImage
* @param int $positionX
* @param int $positionY
* @param int $watermarkImageOpacity
* @param bool $repeat
*/
public function watermark($watermarkImage, $positionX = 0, $positionY = 0, $watermarkImageOpacity = 30, $repeat = false)
{
Varien_Profiler::start(__METHOD__);
/** @var $watermark Imagick */
$watermark = new Imagick($watermarkImage);
//better method to blow up small images.
$watermark->setimageinterpolatemethod(Imagick::INTERPOLATE_NEARESTNEIGHBOR);
if ($this->_watermarkImageOpacity == null) {
$opc = $watermarkImageOpacity;
} else {
$opc = $this->getWatermarkImageOpacity();
}
$watermark->evaluateImage(Imagick::EVALUATE_MULTIPLY, $opc, Imagick::CHANNEL_ALPHA);
// how big are the images?
$iWidth = $this->getImageMagick()->getImageWidth();
$iHeight = $this->getImageMagick()->getImageHeight();
//resize watermark to configuration size
if ($this->getWatermarkWidth() && $this->getWatermarkHeigth() && $this->getWatermarkPosition() != self::POSITION_STRETCH) {
$watermark->scaleImage($this->getWatermarkWidth(), $this->getWatermarkHeigth());
}
// get watermark size
$wWidth = $watermark->getImageWidth();
$wHeight = $watermark->getImageHeight();
//check if watermark is still bigger then image.
if ($iHeight < $wHeight || $iWidth < $wWidth) {
// resize the watermark
$watermark->scaleImage($iWidth, $iHeight);
// get new size
$wWidth = $watermark->getImageWidth();
$wHeight = $watermark->getImageHeight();
}
$x = 0;
$y = 0;
switch ($this->getWatermarkPosition()) {
case self::POSITION_CENTER:
$x = ($iWidth - $wWidth) / 2;
$y = ($iHeight - $wHeight) / 2;
break;
case self::POSITION_STRETCH:
$watermark->scaleimage($iWidth, $iHeight);
break;
case self::POSITION_TOP_RIGHT:
$x = $iWidth - $wWidth;
break;
case self::POSITION_BOTTOM_LEFT:
$y = $iHeight - $wHeight;
break;
case self::POSITION_BOTTOM_RIGHT:
$x = $iWidth - $wWidth;
$y = $iHeight - $wHeight;
break;
default:
break;
}
$this->getImageMagick()->compositeImage($watermark, Imagick::COMPOSITE_OVER, $x, $y);
$watermark->clear();
$watermark->destroy();
Varien_Profiler::stop(__METHOD__);
}
示例7: createBowl
/**
*
* @param string $dishUrl
* @param int $w Width of the Output Image
* @param int $h Height of Output Image
* @return string Path of genrated Image
*/
public function createBowl($dishUrl = null, $w = 140, $h = 0)
{
$bowl = new Imagick("tmpl/img/bowl.png");
$mask = new Imagick("tmpl/img/mask.png");
$dish = new Imagick($dishUrl);
$dish->scaleimage($bowl->getimagewidth(), $bowl->getimageheight());
// Set As per bowl image
$dish->compositeimage(new Imagick("tmpl/img/mask.png"), \Imagick::COMPOSITE_COPYOPACITY, 0, 0, Imagick::CHANNEL_ALPHA);
$dish->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$bowl->compositeimage($dish, \Imagick::COMPOSITE_ATOP, 0, 0, Imagick::CHANNEL_ALPHA);
$bowl->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$bowl->setimageformat("jpg");
$bowl->setImageFileName($url = "img_tmp/" . $this->randomString(10) . "-GE.jpg");
// $bowl->setinterlacescheme(\Imagick::INTERLACE_PNG);
$bowl->scaleimage($w, $h);
$bowl->writeimage();
$bowl->destroy();
return $url;
}
示例8: ScaledImg
public function ScaledImg($cols, $rows)
{
parent::scaleimage($cols, $rows);
}
示例9: array
$image = null;
if (!empty($_REQUEST["Id"]) && ($EnId = intval($_REQUEST["Id"]))) {
if (!empty($_REQUEST["picDelete"])) {
safe_w_sql("DELETE FROM Photos WHERE PhEnId={$EnId}");
}
if (!empty($_REQUEST["picEncoded"])) {
$picEncoded = str_replace(array('data:image/png;base64,', ' '), array('', '+'), $_REQUEST["picEncoded"]);
$im = new Imagick();
$im->setFormat('jpg');
if ($im->readImageBlob(base64_decode($picEncoded))) {
$w = $im->getImageWidth();
$h = $im->getimageheight();
// echo $w . "." . $h;exit;
if ($w != MAX_WIDTH or $h != MAX_HEIGHT) {
// resize image
$im->scaleimage($w / $h < MAX_WIDTH / MAX_HEIGHT ? MAX_WIDTH : 0, $w / $h < MAX_WIDTH / MAX_HEIGHT ? 0 : MAX_HEIGHT);
$w = $im->getImageWidth();
$h = $im->getimageheight();
$im->cropimage(MAX_WIDTH, MAX_HEIGHT, ($w - MAX_WIDTH) / 2, ($h - MAX_HEIGHT) / 2);
}
$imgtoSave = StrSafe_DB(base64_encode($im->getImageBlob()));
safe_w_sql("insert into Photos set PhEnId={$EnId}, PhPhoto={$imgtoSave} on duplicate key update PhPhoto={$imgtoSave}");
require_once 'Common/CheckPictures.php';
updatePhoto($EnId);
}
}
$Sql = "SELECT EnId, CONCAT(EnDivision, '-',EnClass) as Category, CONCAT(CoName, ' (' ,CoCode,')') as Country, CONCAT(UPPER(EnFirstName),' ' ,EnName) as Athlete, PhPhoto as Photo " . "FROM Entries " . "LEFT JOIN Countries ON EnCountry=CoId " . "LEFT JOIN Photos ON EnId=PhEnId " . "WHERE EnTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND EnId=" . StrSafe_DB($_REQUEST['Id']);
$Rs = safe_r_sql($Sql);
if (safe_num_rows($Rs)) {
$row = safe_fetch($Rs);
$Answer .= '<athlete>' . '<id>' . $row->EnId . '</id>' . '<ath><![CDATA[' . $row->Athlete . ']]></ath>' . '<team><![CDATA[' . $row->Country . ']]></team>' . '<cat><![CDATA[' . $row->Category . ']]></cat>' . '<pic><![CDATA[' . ($row->Photo ? "data:image/jpeg;base64," . $row->Photo : '') . ']]></pic>' . '</athlete>';
示例10: createThali
public function createThali($dishArray = array(), $is_thali, $w = 140, $h = 0)
{
Configure::write('debug', 2);
ini_set("max_execution_time", -1);
$thali1 = new Imagick("tmpl/img/thali-1.png");
$thali2 = new Imagick("tmpl/img/thali-2.png");
$thali3 = new Imagick("tmpl/img/thali-3.png");
$mask_1 = new Imagick("tmpl/img/thali-mask2.png");
$mask_2 = new Imagick("tmpl/img/thali-mask3.png");
if (!is_array($dishArray)) {
return false;
}
$mask_cnt = 0;
foreach ($dishArray as $dish) {
if ($mask_cnt > 1) {
// Mask Locking (Modify if masks will be increased or decreased)
break;
}
$dish = new Imagick($dish);
$dish->scaleimage($thali1->getimagewidth(), $thali1->getimageheight());
// Set As per bowl image
if ($is_thali) {
if ($mask_cnt == 1) {
$dish->rotateimage("#fff", 180);
}
$dish->compositeimage(new Imagick("tmpl/img/thali-mask" . ($mask_cnt + 2) . ".png"), \Imagick::COMPOSITE_COPYOPACITY, 0, 0, Imagick::CHANNEL_ALPHA);
$dish->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$thali1->compositeimage($dish, \Imagick::COMPOSITE_ATOP, 0, 0, Imagick::CHANNEL_ALPHA);
$thali1->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$thali2->compositeimage($dish, \Imagick::COMPOSITE_ATOP, 0, 0, Imagick::CHANNEL_ALPHA);
$thali2->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$thali3->compositeimage($dish, \Imagick::COMPOSITE_ATOP, 0, 0, Imagick::CHANNEL_ALPHA);
$thali3->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
} else {
$thali3 = $dish;
}
$mask_cnt++;
}
$url = "files/thali_images/" . $this->randomString(6);
$url_end = "-Thali.jpg";
$result_urls = array();
$thali1->setimageformat("jpg");
$thali1->setImageFileName($result_urls[] = $url . "-0" . $url_end);
$thali1->scaleimage($w, $h);
if ($is_thali) {
$thali2->writeimage();
}
$thali1->destroy();
$thali2->setimageformat("jpg");
$thali2->setImageFileName($result_urls[] = $url . "-1" . $url_end);
$thali2->scaleimage($w, $h);
if ($is_thali) {
$thali2->writeimage();
}
$thali2->destroy();
$thali3->setimageformat("jpg");
$thali3->setImageFileName($result_urls[] = $url . "-2" . $url_end);
$thali3->scaleimage($w, $h);
$thali3->writeimage();
$thali3->destroy();
return $result_urls;
}
示例11: genImgRunner
private function genImgRunner($rugpngs, $colors = array(), $location = "files/temp/")
{
if (is_file($location . "runner.png")) {
return $location;
}
ini_set("max_execution_time", -1);
$layers = array();
$bg = null;
foreach ($rugpngs as $rp) {
if ($rp['type'] == "LAYER") {
$layers[] = new Imagick($rp['path']);
} else {
$bg = new Imagick($rp['path']);
}
}
if ($bg == NULL) {
$bg = new Imagick();
$bg->newImage(910, 475, new ImagickPixel('none'));
$bg->setimageformat('png');
}
foreach ($layers as $layer) {
//$layer->resizeImage(910, 475, Imagick::FILTER_LANCZOS, 1, TRUE);
$layer->setimageformat("png");
}
$bg->resizeImage($layer->getimagewidth(), $layer->getimageheight(), Imagick::FILTER_LANCZOS, 1, TRUE);
$bg->setimageformat("png");
$cnt_a = 0;
foreach ($layers as $layer) {
$layer->paintopaqueimage(new ImagickPixel('#000'), $colors[$cnt_a], 900000);
$bg->compositeimage($layer, \Imagick::COMPOSITE_MULTIPLY, 0, 0);
$cnt_a++;
$layer->destroy();
}
$bg->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$bg = $this->getBgPresp($bg, 60);
$rnd = new Imagick("files/templates/new/runner/angle.png");
$bg->scaleimage(0, $rnd->getimageheight());
$rnd->compositeimage($bg, \Imagick::COMPOSITE_MULTIPLY, 0, 0);
$rnd->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$rnd->compositeimage(new Imagick("files/templates/new/runner/angle_trim.png"), \Imagick::COMPOSITE_COPYOPACITY, 0, 0, Imagick::CHANNEL_ALPHA);
$rnd->setimageformat("png");
$rnd->setImageFileName($location . "runner.png");
$rnd->setinterlacescheme(\Imagick::INTERLACE_PNG);
$rnd->scaleimage(733, 0);
$rnd->writeimage();
$rnd->destroy();
$rnd = new Imagick("files/templates/new/runner/flip.png");
$bg->scaleimage(0, $rnd->getimageheight());
$rnd->compositeimage($bg, \Imagick::COMPOSITE_MULTIPLY, 0, 0);
$rnd->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$rnd->compositeimage(new Imagick("files/templates/new/runner/flip_trim.png"), \Imagick::COMPOSITE_COPYOPACITY, 0, 0, Imagick::CHANNEL_ALPHA);
$rnd->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$rnd->compositeimage(new Imagick("files/templates/new/runner/flip.png"), \Imagick::COMPOSITE_DSTOVER, 0, 0, Imagick::CHANNEL_ALPHA);
$rnd->setimageformat("png");
$rnd->setImageFileName($location . "runner1.png");
$rnd->setinterlacescheme(\Imagick::INTERLACE_PNG);
$rnd->scaleimage(733, 0);
$rnd->writeimage();
$rnd->destroy();
$rnd = new Imagick("files/templates/new/runner/straight.png");
$bg->scaleimage($rnd->getimagewidth(), 0);
$rnd->compositeimage($bg, \Imagick::COMPOSITE_MULTIPLY, 0, 0);
$rnd->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$rnd->compositeimage(new Imagick("files/templates/new/runner/straight_trim.png"), \Imagick::COMPOSITE_COPYOPACITY, 0, 0, Imagick::CHANNEL_ALPHA);
$rnd->setimageformat("png");
$rnd->setImageFileName($location . "runner2.png");
$rnd->setinterlacescheme(\Imagick::INTERLACE_PNG);
$rnd->scaleimage(733, 0);
$rnd->writeimage();
$rnd->destroy();
/*
$rnd = new Imagick("files/templates/runner/runners-4.png");
$rnd->compositeimage($bg, \Imagick::COMPOSITE_MULTIPLY, 0, 200);
$rnd->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$rnd->compositeimage(new Imagick("files/templates/runner/runners-4.png"), \Imagick::COMPOSITE_COPYOPACITY, 0, 0, Imagick::CHANNEL_ALPHA);
$rnd->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$rnd->compositeimage(new Imagick("files/templates/runner/runners-5.png"), \Imagick::COMPOSITE_DEFAULT, 0, 0, Imagick::CHANNEL_ALPHA);
$rnd->setimageformat("png");
$rnd->setImageFileName($location . "runner3.png");
$rnd->writeimage();
$rnd->destroy();
*/
return $location;
}
示例12: createThali
public function createThali($dishArray = array(), $w = 140, $h = 0)
{
Configure::write('debug', 2);
ini_set("max_execution_time", -1);
$thali = new Imagick("tmpl/img/thali.png");
$mask_1 = new Imagick("tmpl/img/thali-mask1.png");
$mask_2 = new Imagick("tmpl/img/thali-mask2.png");
$mask_3 = new Imagick("tmpl/img/thali-mask3.png");
$mask_4 = new Imagick("tmpl/img/thali-mask4.png");
$mask_5 = new Imagick("tmpl/img/thali-mask5.png");
if (!is_array($dishArray)) {
return false;
}
$mask_cnt = 0;
foreach ($dishArray as $dish) {
if ($mask_cnt > 4) {
// Mask Locking (Modify if masks will be increased or decreased)
break;
}
$dish = new Imagick($dish);
if ($mask_cnt + 1 == 5) {
$dish = new Imagick("tmpl/dishes/rice.jpg");
// Fixed Rice for Mask No. 1
}
$dish->scaleimage($thali->getimagewidth(), $thali->getimageheight());
// Set As per bowl image
$dish->compositeimage(new Imagick("tmpl/img/thali-mask" . ($mask_cnt + 1) . ".png"), \Imagick::COMPOSITE_COPYOPACITY, 0, 0, Imagick::CHANNEL_ALPHA);
$dish->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$thali->compositeimage($dish, \Imagick::COMPOSITE_ATOP, 0, 0, Imagick::CHANNEL_ALPHA);
$thali->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
$mask_cnt++;
}
$thali->setimageformat("jpg");
$thali->setImageFileName($url = "files/thali_images/" . $this->randomString(6) . "-Thali.jpg");
// $thali->setinterlacescheme(\Imagick::INTERLACE_PNG);
$thali->scaleimage($w, $h);
$thali->writeimage();
$thali->destroy();
return $url;
}
示例13: renderSvg
/**
* Generates a render of schedule's SVG. The PNG render of the image will be
* stored in /img/schedules/ with a filename equal to the id of the schedule.
* @param $svg string The SVG code for the image
* @param $id string The ID of the schedule, for file name generation
* @return bool True on success, False otherwise.
*/
function renderSvg($svg, $id)
{
try {
// Prepend parsing info
$svg = preg_replace('/(.*<svg[^>]* width=")(100\\%)(.*)/', '${1}1000px${3}', $svg);
$svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $svg;
// Load the image into an ImageMagick object
$im = new Imagick();
$im->readimageblob($svg);
// Convert it to png
$im->setImageFormat("png24");
$im->scaleimage(1000, 600, true);
// Write it to the filesystem
$im->writeimage("../img/schedules/{$id}.png");
$im->clear();
$im->destroy();
// Success!
return true;
} catch (Exception $e) {
return false;
}
}
示例14: cropImg
public function cropImg()
{
//Configure::write('debug', 2);
if ($this->request->is(array("ajax", "post"))) {
$d = $this->request->data;
$url = ltrim($d['uri'], "https://www.pickmeals.com/");
$im = new Imagick($url);
$im->cropimage($d['w'], $d['h'], $d['x'], $d['y']);
$im->scaleimage(253, 0);
$im->writeimage($url);
$im->destroy();
$this->autoRender = false;
$this->response->type('json');
$this->response->body(json_encode(array("error" => 0)));
} else {
exit;
}
}