本文整理匯總了PHP中Imagick::writeimage方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::writeimage方法的具體用法?PHP Imagick::writeimage怎麽用?PHP Imagick::writeimage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::writeimage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: serverAction
public function serverAction(Request $request)
{
$fileName = $request->get('fileName');
$points = $request->get('transform');
$sizes = $this->getSizes();
$fileFullName = $sizes[0]['dir'] . $fileName;
try {
$image = new \Imagick($fileFullName);
} catch (\ImagickException $e) {
return new JsonResponse(array('success' => false, 'errorMessage' => 'На сервере не найден файл'));
}
$finalScale = $sizes[0]['width'] / $sizes[0]['mediumWidth'];
for ($i = 0; $i <= 5; $i++) {
$points[$i] *= $finalScale;
}
$image->distortImage(\Imagick::DISTORTION_AFFINEPROJECTION, $points, TRUE);
$image->cropImage($sizes[0]['width'], $sizes[0]['height'], 0, 0);
$hashFile = md5_file($fileFullName);
$fileName = $hashFile . '.jpg';
foreach ($sizes as $size) {
$imgFullName = $size['dir'] . $fileName;
$image->thumbnailImage($size['width'], $size['height'], TRUE);
$image->writeimage($imgFullName);
if (!file_exists($imgFullName)) {
$image->writeimage($imgFullName);
}
}
return new JsonResponse(array('success' => true, 'fileName' => $fileName));
}
示例2: crop
/**
* @param integer $x
* @param integer $y
* @param integer $width
* @param integer $height
*
* @return boolean
*/
public function crop($x, $y, $width, $height)
{
try {
$this->imagick->cropimage($width, $height, $x, $y);
$this->imagick->writeimage($this->pathToUploadDir . $this->file->getPath());
$this->file->getParams()->setWidth($width);
$this->file->getParams()->setHeight($height);
$this->entityManager->flush();
return true;
} catch (\Exception $exception) {
return false;
}
}
示例3: setBackground
public function setBackground($file)
{
if (empty($this->pdf)) {
die('Set layout before');
}
if (!is_file($file)) {
die('Incorect background file');
}
$tmp = $this->getTmpFilePath('pdf');
$img = new Imagick($file);
$img->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
$img->setresolution(300, 300);
$img->setimageformat('pdf');
$img->writeimage($tmp);
$this->pdf->setSourceFile($tmp);
$this->pdf->SetMargins(0, 0, 0, true);
$tplIdx = $this->pdf->importPage(1);
$this->pdf->useTemplate($tplIdx, null, null, 0, 0, true);
$this->pdf->SetMargins(0, 0, 0, true);
$this->pdf->setCellHeightRatio(1);
$this->pdf->setCellPaddings(0, 0, 0, 0);
$this->pdf->setCellMargins(1, 1, 1, 1);
$this->pdf->SetAutoPageBreak(false);
$this->pdf->SetPrintHeader(false);
$this->pdf->SetPrintFooter(false);
}
示例4: cropImage
public static function cropImage($dataPathRoot, $imageFileRelativeName, $imageThumbFileRelativeName, $width, $height)
{
$cloudStorage = CloudHelper::getCloudModule(CloudHelper::CLOUD_MODULE_STORAGE);
$tempSrcFilePath = $cloudStorage->createTempFileForStorageFile($dataPathRoot, $imageFileRelativeName);
$tempDestFilePath = $cloudStorage->getTempFilePath();
//生成縮略圖
if (extension_loaded('imagick')) {
// 如果有 imagick 模塊,優先選擇 imagick 模塊,因為生成的圖片質量更高
$img = new \Imagick($tempSrcFilePath);
$img->stripimage();
//去除圖片信息
$img->setimagecompressionquality(95);
//保證圖片的壓縮質量,同時大小可以接受
$img->cropimage($width, $height, 0, 0);
$img->writeimage($tempDestFilePath);
$cloudStorage->moveFileToStorage($dataPathRoot, $imageThumbFileRelativeName, $tempDestFilePath);
//主動釋放資源,防止程序出錯
$img->destroy();
unset($img);
} else {
// F3 框架的 Image 類限製隻能操作 UI 路徑中的文件,所以我們這裏需要設置 UI 路徑
global $f3;
$f3->set('UI', dirname($tempSrcFilePath));
$img = new \Image('/' . basename($tempSrcFilePath));
$img->resize($width, $height, true);
$img->dump('jpeg', $tempDestFilePath);
$cloudStorage->moveFileToStorage($dataPathRoot, $imageThumbFileRelativeName, $tempDestFilePath);
//主動釋放資源,防止程序出錯
$img->__destruct();
unset($img);
}
// 刪除臨時文件
@unlink($tempSrcFilePath);
@unlink($tempDestFilePath);
}
示例5: property
public function property()
{
$im = new Imagick();
$im->newimage(50, 50, 'blue');
$im->setimageformat('jpg');
$im->setimageproperty('comment', 'rawr');
var_dump($im->getimageproperty('comment'));
$im->writeimage(getcwd() . '/images/test/output.jpg');
echo '<br />' . var_dump($im->getimageproperty('comment'));
echo '<img src="/images/test/output.jpg" /><br />';
$this->read();
}
示例6: start
public function start()
{
//var_dump($this->filename, $this->uploadfile);
if (move_uploaded_file($this->tmpfilename, $this->uploadfile)) {
$img = new Imagick($this->uploadfile);
$img->resizeimage($this->h, $this->w, Imagick::FILTER_LANCZOS, 1);
$img->writeimage($this->uploadfile);
$img->destroy();
return $this->uploaddir . $this->filenewname;
}
//echo 'not found';
return false;
}
示例7: convertPDF
protected static function convertPDF($file)
{
if ("%PDF-" === file_get_contents($file, null, null, 0, 5)) {
// magic!
if (class_exists('Imagick')) {
$img = new \Imagick($file . '[0]');
$img->setimageformat("jpg");
$img->writeimage($file);
} else {
exec(sprintf('convert %s[0] %s', escapeshellarg($file), escapeshellarg($file . '.jpg')));
rename($file . '.jpg', $file);
}
}
}
示例8: storeCover
public function storeCover(BookInterface $book, $cover)
{
#/conifg/filesystems.php
$ebook_path = "{$book->id}/Resources/Templates/ebook/cover.jpg";
$print_path = storage_path("books/{$book->id}/Resources/Templates/print");
Storage::disk('book_local')->put($ebook_path, File::get($cover));
Storage::disk('book_local')->put("{$book->id}/Resources/Templates/cover.jpg", File::get($cover));
if (!is_dir($print_path)) {
mkdir($print_path, 0775, true);
// argumento true criar pastas recursivamente
}
$img = new \Imagick($ebook_path);
$img->setimageformat("pdf");
$img->writeimage($print_path . '/cover.pdf');
}
示例9: pdfthumb
function pdfthumb($src)
{
if (!$src || !file_exists(realpath($src))) {
return '';
}
$infos = pathinfo(realpath($src));
$cachedFile = 'application/cache/pdfsthumbs/' . str_replace('/', '-', str_replace(realpath(BASEPATH . '/../') . '/', '', $infos['dirname'] . '/' . $infos['filename'])) . '.png';
if (file_exists($cachedFile)) {
return $cachedFile;
}
$source = realpath($src);
$im = new Imagick($source);
$im->setiteratorindex(0);
$im->setcompressionquality(90);
$im->writeimage($cachedFile);
return $cachedFile;
}
示例10: renderCustomBitDepthPNG
function renderCustomBitDepthPNG()
{
$imagePath = $this->control->getImagePath();
$imagick = new \Imagick(realpath($imagePath));
$imagick->setImageFormat('png');
$imagick->setOption('png:bit-depth', '16');
$imagick->setOption('png:color-type', 6);
header("Content-Type: image/png");
$crash = true;
if ($crash) {
echo $imagick->getImageBlob();
} else {
$tempFilename = tempnam('./', 'imagick');
$imagick->writeimage(realpath($tempFilename));
echo file_get_contents($tempFilename);
}
}
示例11: 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__);
}
}
示例12: parseItems
protected function parseItems($xpath, $html, &$items)
{
$crawler = new Crawler();
$crawler->addHtmlContent($html);
foreach ($crawler->filterXPath($xpath) as $tr) {
$item = array();
$tds = $tr->getElementsByTagName('td');
if (0 == $tds->length) {
continue;
}
$item['id'] = (int) ($item['value'] = str_replace(array("\n", "'"), '', $tds->item(1)->nodeValue));
$name = $tds->item(3);
$sup = $name->getElementsByTagName('sup')->item(0);
if (null !== $sup) {
$name->removeChild($sup);
}
$item['name'] = $item['label'] = str_replace(array("\n", "'"), '', $name->nodeValue);
/** @var \DOMElement $tds */
if ($tds->item(4)->getElementsByTagName('a')->length > 0) {
$title = $tds->item(4)->getElementsByTagName('a')->item(0)->getAttribute('title');
} else {
continue;
}
$item['title'] = $title;
if ($tds->item(0)->childNodes->length != 0 && $tds->item(0)->childNodes->item(0)->nodeName == 'a' && $tds->item(0)->childNodes->item(0)->childNodes->item(0)->nodeName == 'img') {
$image = file_get_contents($tds->item(0)->childNodes->item(0)->childNodes->item(0)->getAttribute('src'));
$storepath = sprintf('/var/www/MControl/images/%s.png', str_replace(':', '_', $item['name']));
/** @var \Imagick $croppedImage */
$croppedImage = new \Imagick();
$croppedImage->readimageblob($image);
$croppedImage->cropimage(25, 12, 0, 0);
$croppedImage->writeimage($storepath);
$palette = $this->colorPalette($storepath, 2);
$item['color'] = str_split($palette[1], 2);
} else {
$item['color'] = null;
}
$items[] = $item;
}
return $items;
}
示例13: uploaderAction
public function uploaderAction(Request $request)
{
// Получение переданных файлов и информации об альбоме из запроса
$file = $_FILES['uploadedImages'];
$tmpFileName = $file['tmp_name'];
if (is_uploaded_file($tmpFileName)) {
chmod($tmpFileName, 0660);
}
$albumID = $request->get('albumID');
// Создание экземпляра Imagick и образка изображение до нужного размера
try {
$image = new \Imagick($tmpFileName);
} catch (\ImagickException $e) {
return new JsonResponse(array('success' => false, 'errorMessage' => ["Файл {$file['tmp_name']} не загрузился"]));
}
$image->cropImage(800, 800, 0, 0);
// Формирование нового имени файла
$hashFile = md5_file($tmpFileName);
$newFileName = $hashFile . '.jpg';
// Сохранение файла в папки
$uploadDir = $request->server->get('DOCUMENT_ROOT') . '/uploaded/images';
$imagePaths = array('800x800' => "{$uploadDir}/800x800/", '200x200' => "{$uploadDir}/200x200/");
foreach ($imagePaths as $size => $path) {
$dimensions = explode('x', $size);
$image->thumbnailImage((int) $dimensions[0], (int) $dimensions[1], true, false);
$image->writeimage($path . $newFileName);
}
// Сохранение информации о файле в базе
$em = $this->getDoctrine()->getManager();
$album = $em->getRepository('PhotoBundle:Album')->find($albumID);
if (!$album) {
return new JsonResponse(array('success' => false, 'errorMessage' => ["Переданы не корректные парраметры"]));
}
$photo = new Photo();
$photo->setAlbum($album)->setEnabled(1)->setName($newFileName);
$em->persist($photo);
$em->flush();
$images = array('success' => true, 'fileName' => $newFileName);
//$images = '';
return new JsonResponse($images);
}
示例14: 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;
}
示例15: 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;
}