略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Imagick::setImageOrientation

2024-11-14

Imagick::setImageOrientation

(PECL imagick 2, PECL imagick 3)

Imagick::setImageOrientationSets the image orientation

说明

public Imagick::setImageOrientation(int $orientation): bool

Sets the image orientation.

参数

orientation

One of the orientation constants

返回值

成功时返回 true

范例

示例 #1 Imagick::setImageOrientation()

<?php
//Doesn't appear to do anything
function setImageOrientation($imagePath$orientationType) {
    
$imagick = new \Imagick(realpath($imagePath));
    
$imagick->setImageOrientation($orientationType);
    
header("Content-Type: image/jpg");
    echo 
$imagick->getImageBlob();
}

?>
add a noteadd a note

User Contributed Notes 1 note

up
4
orrd101 at yahoo dot com
9 years ago
Be aware that Imagick::setImageOrientation() doesn't actually rotate the image, it just changes the EXIF rotation info that will be saved with the image. In some cases that may be what you want to do, but  if you're trying to rotate an image, this probably isn't the way you want to do it. The problem with relying on the EXIF rotation info is that many web browsers ignore and some image viewing software ignore the EXIF information and don't auto-rotate it automatically.  This function is best used to correct EXIF rotation information just before saving an image.

To actually rotate an image, use Imagick::rotateImage(). 

And then maybe use this function to save the correct EXIF orientation data.  For example: $image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);

官方地址:https://www.php.net/manual/en/imagick.setimageorientation.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3