phpで簡単に画像を合成。Image_Combinationを作成しました。

phpImageMagickライブラリの方が沢山機能があって便利だと思います。

phpのGDを利用して画像合成するライブラリ作ってみよと思いまして遊び半分で作成しました。

openpearチャンネルのインストール&Image_Combinationのインストール

pear channel-discover openpear.org
sudo pear install openpear/Image_Combination-alpha 

画像の合成&セーブ

<?php

require_once ('Image/Combination.php');

$image = new Image_Combination(100,100);
$image->setImageType('gif');
$image->push(array('file' => 'body.gif',   'x' => 30, 'y' => 5));
$image->push(array('file' => 'weapon.gif', 'x' => 5,  'y' => 35));
$image->push(array('file' => 'shield.gif', 'x' => 55, 'y' => 45));
$image->save('person.gif');

画像の合成&出力

<?php
require_once ('Image/Combination.php');

$image = new Image_Combination(100,100);
$image->setImageType('gif');
$image->push(array('file' => 'body.gif',   'x' => 30, 'y' => 5));
$image->push(array('file' => 'weapon.gif', 'x' => 5,  'y' => 35));
$image->push(array('file' => 'shield.gif', 'x' => 55, 'y' => 45));
$image->output();





まとめ

頭の体操にちょうど良かったかな。どうだろう。


[PR]Spreeの情報を集めています。

ECを持ちたい方、仕事でECを使いたい方向けのコミュニティサイトです。
このサイトでは世界で最も使用されているECの1つであるSpreeについての情報を提供しています。
http://spreecommerce.jp/