Bulgaria PHP Conference 2019

# Imagick::rotateImage

(PECL imagick 2.0.0)

Imagick::rotateImageRotates an image

### Описание

Imagick::rotateImage ( mixed `\$background` , float `\$degrees` ) : bool

Rotates an image the specified number of degrees. Empty triangles left over from rotating the image are filled with the background color.

### Список параметров

`background`

The background color

`degrees`

Rotation angle, in degrees. The rotation angle is interpreted as the number of degrees to rotate the image clockwise.

### Возвращаемые значения

В случае успешной работы возвращает `TRUE`.

### Список изменений

Версия Описание
2.1.0 Now allows a string representing the color as the first parameter. Previous versions allow only an ImagickPixel object.

### Примеры

Пример #1 Imagick::rotateImage()

``` <?phpfunction rotateImage(\$imagePath, \$angle, \$color) {    \$imagick = new \Imagick(realpath(\$imagePath));    \$imagick->rotateimage(\$color, \$angle);    header("Content-Type: image/jpg");    echo \$imagick->getImageBlob();}?> ``` add a note

### User Contributed Notes 5 notes

gleb dot deykalo at gmail dot com
3 years ago
``` Some transformations including Imagick ::rotateImage() may change "image page" -- working area inside the image you work on.Be careful with future modifications afterwards because the image page would be different from new sizes of the image.For example, if you do Imagic::cropImage() after rotation, you need to set image page properly, otherwise your crop would be performed relating to wrong coordinates (depending on rotation angle, resulting image size may vary).<?php\$Image = new Imagick(\$sourceImagePath);\$transparent = '#00000000';\$Image->rotateImage(new \ImagickPixel(), 45); // This makes resulting image bigger// Set page to be of the full size of new image, starting at top left corner (0, 0)\$Image->setImagePage(\$Image->getImageWidth(), \$Image->getImageHeight(), 0, 0);\$Image->cropImage(\$crop_w, \$crop_h, \$crop_x, \$crop_y);?> ```
Anonymous
3 years ago
``` The degrees for imagick and gd is difference!GD > rotate 90 means counter clockwise.Imagick > rotate 90 means clockwise.GD 90 = Imagick 270 or Imagick 90 = GD 270.Use this function.<?phpfunction calculateCounterClockwise(\$value){    if (\$value == 0 || \$value == 180) {        return \$value;    }    if (\$value < 0 || \$value > 360) {        \$value = 90;    }    \$total_degree = 360;    \$output = intval(\$total_degree-\$value);    return \$output;}// calculateCounterClockwiseecho '1 = '.calculateCounterClockwise(1).'<br>';echo '90 = '.calculateCounterClockwise(90).'<br>';echo '270 = '.calculateCounterClockwise(270).'<br>';echo '359 = '.calculateCounterClockwise(359).'<br>';echo '360 = '.calculateCounterClockwise(360).'<br>';?>test results:1 = 35990 = 270270 = 90359 = 1360 = 0 ```
AlexG
6 years ago
``` Transparent <?php \$im->rotateImage(new ImagickPixel('#00000000'), 75); ?> ```
-3
wjsams at gmail dot com
10 years ago
``` If you want to rotate an image by a certain degree you can do this: <?php header('content-type: image/jpeg'); \$imagick = new Imagick(); \$imagick->readImage('castle.jpg'); \$imagick->rotateImage(new ImagickPixel(), 90); print \$imagick->getImage(); ?> ```
-10
Baptiste VALTHIER
8 years ago
``` You can rotate an jpg image by -13.55° into a transparent png image with : <?php \$imagick = new Imagick(); \$imagick->readImage('my.jpg'); \$imagick->rotateImage(new ImagickPixel('none'), -13.55); \$imagick->writeImage('my_rotated.png'); \$imagick->clear(); \$imagick->destroy(); ?> ```
{"ft_lang_label":"__label__en","ft_lang_prob":0.6891497,"math_prob":0.7355762,"size":727,"snap":"2019-35-2019-39","text_gpt3_token_len":171,"char_repetition_ratio":0.14799447,"word_repetition_ratio":0.0,"special_character_ratio":0.25447044,"punctuation_ratio":0.20325203,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9581342,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-09-18T15:34:11Z\",\"WARC-Record-ID\":\"<urn:uuid:a47db0d2-f396-4551-9893-03103c59dbd4>\",\"Content-Length\":\"105090\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a0ec1e03-a1fb-436a-9301-11e06802423f>\",\"WARC-Concurrent-To\":\"<urn:uuid:277b8e06-04f5-4f40-8649-ea92339dd324>\",\"WARC-IP-Address\":\"185.85.0.29\",\"WARC-Target-URI\":\"https://www.php.net/manual/ru/imagick.rotateimage.php\",\"WARC-Payload-Digest\":\"sha1:46R5VIEWHXARO3SSOHDN5FV3ZGPM5Q2C\",\"WARC-Block-Digest\":\"sha1:SE3Q4JGNXK6PTD3U3DG2UAMDJWPLCLTO\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-39/CC-MAIN-2019-39_segments_1568514573309.22_warc_CC-MAIN-20190918151927-20190918173927-00129.warc.gz\"}"}