本文整理匯總了PHP中Imagick::getImageHeight方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::getImageHeight方法的具體用法?PHP Imagick::getImageHeight怎麽用?PHP Imagick::getImageHeight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::getImageHeight方法的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: thumbImage
public static function thumbImage($imgPath, $width, $height, $blur = 1, $bestFit = 0, $cropZoom = 1)
{
$dir = dirname($imgPath);
$imagick = new \Imagick(realpath($imgPath));
if ($imagick->getImageHeight() > $imagick->getImageWidth()) {
$w = $width;
$h = 0;
} else {
$h = $height;
$w = 0;
}
$imagick->resizeImage($w, $h, $imagick::DISPOSE_UNDEFINED, $blur, $bestFit);
$cropWidth = $imagick->getImageWidth();
$cropHeight = $imagick->getImageHeight();
if ($cropZoom) {
$imagick->cropImage($width, $height, ($imagick->getImageWidth() - $width) / 2, ($imagick->getImageHeight() - $height) / 2);
}
$direct = 'thumbs/';
$pathToWrite = $dir . "/" . $direct;
//var_dump($pathToWrite);
if (!file_exists($pathToWrite)) {
mkdir($pathToWrite, 0777, true);
}
$newImageName = 'thumb_' . basename($imgPath);
//var_dump($newImageName);
$imagick->writeImage($pathToWrite . 'thumb_' . basename($imgPath));
return $pathToWrite . $newImageName;
}
示例3: createThumbnailWithImagick
/**
* Creates a thumbnail with imagick.
*
* @param File $fileObject FileObject to add properties
* @param string $httpPathToMediaDir Http path to file
* @param string $pathToMediaDirectory Local path to file
* @param string $fileName Name of the image
* @param string $fileExtension Fileextension
* @param integer $width Width of thumbnail, if omitted, size will be proportional to height
* @param integer $height Height of thumbnail, if omitted, size will be proportional to width
*
* @throws ThumbnailCreationFailedException If imagick is not supported
* @throws InvalidArgumentException If both, height and width are omitted or file format is not supported
*/
private static function createThumbnailWithImagick(File &$fileObject, $httpPathToMediaDir, $pathToMediaDirectory, $fileName, $fileExtension, $width = null, $height = null)
{
if (!extension_loaded('imagick')) {
throw new ExtensionNotLoadedException('Imagick is not loaded on this system');
}
if ($width === null && $height === null) {
throw new InvalidArgumentException('Either width or height must be provided');
}
// create thumbnails with imagick
$imagick = new \Imagick();
if (!in_array($fileExtension, $imagick->queryFormats("*"))) {
throw new ThumbnailCreationFailedException('No thumbnail could be created for the file format');
}
// read image into imagick
$imagick->readImage(sprintf('%s/%s.%s', $pathToMediaDirectory, $fileName, $fileExtension));
// set size
$imagick->thumbnailImage($width, $height);
// null values allowed
// write image
$imagick->writeImage(sprintf('%s/%sx%s-thumbnail-%s.%s', $pathToMediaDirectory, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
$fileObject->setThumbnailLink(sprintf('%s/%sx%s-thumbnail-%s.%s', $httpPathToMediaDir, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
$fileObject->setLocalThumbnailPath(sprintf('%s/%sx%s-thumbnail-%s.%s', $pathToMediaDirectory, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
// free up associated resources
$imagick->destroy();
}
示例4: thumbnail
/**
* @param $file
* @return string
*/
public function thumbnail($file)
{
$format = '';
$name = md5((new \DateTime())->format('c'));
foreach ($this->sizes as $size) {
$image = new \Imagick($file);
$imageRatio = $image->getImageWidth() / $image->getImageHeight();
$width = $size['width'];
$height = $size['height'];
$customRation = $width / $height;
if ($customRation < $imageRatio) {
$widthThumb = 0;
$heightThumb = $height;
} else {
$widthThumb = $width;
$heightThumb = 0;
}
$image->thumbnailImage($widthThumb, $heightThumb);
$image->cropImage($width, $height, ($image->getImageWidth() - $width) / 2, ($image->getImageHeight() - $height) / 2);
$image->setCompressionQuality(100);
$format = strtolower($image->getImageFormat());
$pp = $this->cachePath . '/' . $size['name'] . "_{$name}." . $format;
$image->writeImage($pp);
}
return "_{$name}." . $format;
}
示例5: getSize
/**
* 獲取圖片尺寸
* @return array
*/
public function getSize()
{
$wh = [];
$wh['width'] = $this->image->getImageWidth();
$wh['height'] = $this->image->getImageHeight();
return $wh;
}
示例6: 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);
}
示例7: draw
public function draw(OsuSignature $signature)
{
parent::draw($signature);
if ($this->width != -1 || $this->height != -1) {
$this->image->resizeImage($this->width == -1 ? $this->image->getImageWidth() : $this->width, $this->height == -1 ? $this->image->getImageHeight() : $this->height, 1, $this->filter);
}
$signature->getCanvas()->compositeImage($this->image, $this->composite, $this->x, $this->y);
}
示例8: loadFile
/**
* @see wcf\system\image\adapter\IImageAdapter::loadFile()
*/
public function loadFile($file)
{
try {
$this->imagick->readImage($file);
} catch (\ImagickException $e) {
throw new SystemException("Image '" . $file . "' is not readable or does not exist.");
}
$this->height = $this->imagick->getImageHeight();
$this->width = $this->imagick->getImageWidth();
}
示例9: getSilhouette
function getSilhouette(\Imagick $imagick)
{
$character = new \Imagick();
$character->newPseudoImage($imagick->getImageWidth(), $imagick->getImageHeight(), "canvas:white");
$canvas = new \Imagick();
$canvas->newPseudoImage($imagick->getImageWidth(), $imagick->getImageHeight(), "canvas:black");
$character->compositeimage($imagick, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
$canvas->compositeimage($character, \Imagick::COMPOSITE_ATOP, 0, 0);
$canvas->setFormat('png');
return $canvas;
}
示例10: loadDir
function loadDir($path)
{
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." and $file != "..") {
//skip . and ..
if (is_file($path . '/' . $file)) {
$tmpFile = trim($file);
$ext = pathinfo($file, PATHINFO_EXTENSION);
$File = pathinfo($file, PATHINFO_FILENAME);
$valid_exts = array('jpeg', 'JPEG', 'jpg', 'JPG', 'png', 'PNG', 'gif', 'GIF');
$sizes = array('f' => 45, 't' => 92, 's' => 120, 'm' => 225, 'l' => 300);
//required sizes in WxH ratio
if (in_array($ext, $valid_exts)) {
// if file is image then process it!
foreach ($sizes as $w => $h) {
$image = new Imagick();
$image->readImage($path . '/' . $tmpFile);
$imgWidth = $image->getImageWidth();
$imgHeight = $image->getImageHeight();
$image->resizeImage($h, $h, Imagick::FILTER_LANCZOS, 1);
// resize from array sizes
$fileName .= $File . '_' . $w . '.' . $ext;
//create the image filaname
$image->writeImage($path . '/' . $fileName);
$tempFileName = $path . '/' . $fileName;
$arrayfiles[] = $tempFileName;
$custWidth = $image->getImageWidth();
$custHeight = $image->getImageHeight();
echo "[ Original dimension : {$imgWidth} x {$imgHeight} ] [ Custom dimension : {$custWidth} x {$custHeight} ] Output image location: <a href='{$tempFileName}' style='text-decoration:none'> " . $tempFileName . "</a> ";
echo "<img class='img' src='{$tempFileName}' /></br>";
$w = '';
$h = '';
$fileName = '';
$image->clear();
$image->destroy();
}
//end foreach sizes
}
}
if (is_dir($path . '/' . $file)) {
echo '</br> <div style="height:0;width:1200px;border:0;border-bottom:2px;border-style: dashed;border-color: #000000"></div><span style="font-weight:bold; font-size:14px; color:red ">Directory Name: ';
echo $path . "/" . $file;
echo '</span><div style="height:0;width:1200px;border:0;border-bottom:2px;border-style: dashed;border-color: #000000"></div></br>';
loadDir($path . '/' . $file);
}
}
}
// end while
}
// end handle
}
示例11: 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);
}
示例12: 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;
}
示例13: makeCover
/**
* makeCover - For shortcuts/gallery covers
*/
public static function makeCover($sourceImg, $destImg)
{
$image = new Imagick($sourceImg);
$w_orig = $image->getImageWidth();
$h_orig = $image->getImageHeight();
$w_new = SmIMAGE;
$h_new = SmIMAGE * COVERASPECT;
$ratio_orig = $h_orig / $w_orig;
if ($ratio_orig == COVERASPECT) {
// Only resize
$image->resizeImage($w_new, $h_new, Imagick::FILTER_CATROM, 1, TRUE);
} else {
if ($ratio_orig >= COVERASPECT) {
// Taller than target
$w_temp = $w_new;
$h_temp = $w_new * $ratio_orig;
$w_center = 0;
$h_center = ($h_temp - $h_new) / 2;
} else {
// Wider than target
$w_temp = $h_new / $ratio_orig;
$h_temp = $h_new;
$w_center = ($w_temp - $w_new) / 2;
$h_center = 0;
}
$image->resizeImage($w_temp, $h_temp, Imagick::FILTER_CATROM, 1, TRUE);
$image->cropImage($w_new, $h_new, $w_center, $h_center);
}
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(80);
$image->writeImage($destImg);
$image->destroy();
}
示例14: 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();
}
示例15: addWatermark
public function addWatermark($image_path)
{
try {
// Open the original image
$image = new \Imagick();
$is_success = $image->readImage($image_path);
if ($is_success === FALSE) {
throw new WatermarkException("Cannot read uploaded image");
}
$watermark = new \Imagick();
$is_success = $watermark->readImage($this->_WATERMARK_IMAGE_PATH);
if ($is_success === FALSE) {
throw new WatermarkException("Cannot read uploaded image");
}
$image_width = $image->getImageWidth();
$image_height = $image->getImageHeight();
$watermark_width = $watermark->getImageWidth();
$watermark_height = $watermark->getImageHeight();
$watermark_pos_x = $image_width - $watermark_width - 20;
$watermark_pos_y = 20;
// Overlay the watermark on the original image
$is_success = $image->compositeImage($watermark, \imagick::COMPOSITE_OVER, $watermark_pos_x, $watermark_pos_y);
if ($is_success === FALSE) {
throw new WatermarkException("Cannot save image after watermarked");
}
//Write the image
$image->writeImage($image_path);
} catch (ImagickException $e) {
error_log($e->getMessage());
throw new WatermarkException($e->getMessage(), $e->getCode(), $e);
}
}