$yum install php-imagick としてみたら以下の php-pecl-imagick をインストールできました。
=======================
Package アーキテクチャー バージョン リポジトリー 容量
=======================
インストール中:
php-pecl-imagick-im6 x86_64 3.7.0-1.el7.remi.7.4 remi-php74 185 k
php-pecl-imagick.x86_64 3.4.4-6.el7.remi.7.4 を入れ替えます
依存性関連での更新をします:
ImageMagick6-libs x86_64 6.9.12.34-1.el7.remi remi-safe 2.4 M
php74-php-pecl-imagick x86_64 3.4.4-17.el7.remi remi-safe 137 k
トランザクションの要約
========================================================================================================================================================================================================
インストール 1 パッケージ縦横2000以内にscale
scaleImage(w, h, true); で比率合わせてくれるみたいです。
$max = 2000;
$image_path = 'path/image.jpg';
$watermark_path = '/watermark_path/data/images/watermark.png';
$img = new imagick($image_path);
$water = new imagick($watermark_path);
$w = $img->getImageWidth();
$h = $img->getImageHeight();
if ($w > $max || $h > $max ) {
$rate = $w/$h;
if ($w > $h ) {
$w = $max;
$h = (int)($w/$rate);
} else {
$h = $max;
$w = (int)($h/$rate);
}
$img->scaleImage($w, $h);
} else {
$max = ($w>$h)?$w:$h;
}
// water size wに比例
$water->scaleImage($max/10, $max/10, true);
$ww = $water->getImageWidth();
$wh = $water->getImageHeight();
// composite
$x = ($w/2) - ($ww/2);
$y = ($h/2) - ($wh/2);
$img->compositeImage($water, imagick::COMPOSITE_DEFAULT, $x, $y);
// 保存
$img->writeImage($image_path);
こんな感じでwatermarkを画像にかぶせることができました!



コメント