<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"
dir="ltr">
<head>
<title>sample741(ImageMagick6.4.4)</title>
</head>
<body>
<?php
/* 指定された複数画像ファイルの高さをそろえて連結する(境界はぼかす) */
$fns = array('sample3b.jpg', 'sf.jpg', 'sf2.jpg');
/* 画像の高さ */
$height = 100;
/* ぼかし幅 */
$bw = 20;
$im = new Imagick($fns[0]);
for($ind=1;$ind<count($fns);$ind++){
$imt = new Imagick($fns[$ind]);
$imt->setImageMatte(true);
$imt->resizeImage(0, $height, imagick::FILTER_MITCHELL, 1);
  /* リサイズ後の幅がぼかし幅ピクセル未満は何もしない */
if( $imt->getImageWidth() >= $bw ){
  /* alpha値をぼかし幅だけグラデーションになるように設定 */
  $it = $imt->getPixelIterator();
  foreach($it as $py => $line){
    foreach($line as $px => $pixel){
      if( $px < $bw ){
        $pixel->setColorValue(Imagick::COLOR_ALPHA, $px/$bw);
      }
    }
    $it->syncIterator();
  }
  /* 元画像を拡張 */
  $im->setImageBackgroundColor('none');
  $im->setImageExtent(
    $imt->getImageWidth()-$bw+$im->getImageWidth(), $height);
  $im->compositeImage($imt, Imagick::COMPOSITE_DEFAULT,
    $im->getImageWidth()-$imt->getImageWidth(), 0,
    Imagick::CHANNEL_ALL);
}
$imt->destroy();
}
$im->writeImage('sample741a.png');
$im->destroy();
?>
<img src="sample741a.png" />
</body>
</html>
元画像1(samlpe3b.jpg)

元画像2(sf.jpg)
元画像3(sf2.jpg)

出力画像(sample741a.png)

関連項目
ImageMagickとPHPで複数の画像ファイルの高さをそろえて連結する
ImageMagickとPHPで画像をグレースケールの立体的な角丸四角に変換する
 
No comments:
Post a Comment