日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

php 开启imagick,PHP-Imagick:在Imagick项目上设置重力

發(fā)布時(shí)間:2024/9/27 php 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 开启imagick,PHP-Imagick:在Imagick项目上设置重力 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在Imagick中設(shè)置圖像的重力時(shí),我遇到了一些實(shí)際困難.

我已經(jīng)成功設(shè)置了ImaickDraw對象的重力,但是我沒有成功在Imagick對象中設(shè)置它.

以下是此刻我正在使用的基本代碼.我只是使用了與ImagickDraw相同的方法,但是顯然它沒有用.

$rating = new Imagick("ratings/" . $rating . ".png");

$rating->setGravity (Imagick::GRAVITY_SOUTH);

$im->compositeImage($rating, imagick::COMPOSITE_OVER, 20, 20);

有什么想法如何為現(xiàn)有圖像而不是繪圖對象設(shè)置重力?

謝謝!

解決方法:

在您的情況下,setGravity方法應(yīng)應(yīng)用于$im對象.但是無論如何,重力似乎僅會(huì)影響到用drawImage插入的ImagickDraw對象,并且無法像使用ImageMagick命令那樣將圖像放入繪圖中.

因此,有兩種方法可以做到這一點(diǎn):

1號如果您的主機(jī)允許使用shell_exec或exec函數(shù),則可以運(yùn)行類似的命令.

convert image.jpg -gravity south -\

draw "image Over 0,0 0,0 watermak.png" \

result.jpg`

2號否則,您可以計(jì)算放置在基礎(chǔ)圖像上的圖像的位置,并使用CompositeImage

$imageHight = $im->getImageHeight();

$imageWith = $im->getImageWidth();

// Scale the sprite if needed.

// Here I scale it to have a 1/2 of base image's width

$rating->scaleImage($imageWith / 2, 0);

$spriteWidth = $rating->getImageWidth();

$spriteHeight = $rating->getImageHeight();

// Calculate coordinates of top left corner of the sprite

// inside of the image

$left = ($imageWidth - $spriteWidth)/2; // do not bother to round() values, IM will do that for you

$top = $imageHeight - $spriteHeight;

// If you need bottom offset to be, say, 1/6 of base image height,

// then decrease $top by it. I recommend to avoid absolute values here

$top -= $imageHeight / 6;

$im->compositeImages($rating, imagick::COMPOSITE_OVER, $left, $top);

標(biāo)簽:imagick,imagemagick,php

來源: https://codeday.me/bug/20191208/2091703.html

總結(jié)

以上是生活随笔為你收集整理的php 开启imagick,PHP-Imagick:在Imagick项目上设置重力的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。