Ejemplo n.º 1
0
 /**
  * コンストラクタ。
  * @param int 画像幅(px)
  * @param int 画像高さ(px)
  * @param int 背景画像色 例:0x0099FF
  */
 public function __construct($width, $height, $backgroundColor = 0)
 {
     $imageResource = imagecreatetruecolor($width, $height);
     $this->graphics = new Dm_Image_Graphic_Shape($imageResource, $width, $height);
     $this->textGraphics = new Dm_Image_Graphic_Text($imageResource, $width, $height);
     $this->_imageResource = $imageResource;
     $this->_width = $width;
     $this->_height = $height;
     //背景色設定(透過を有効化)
     imagesavealpha($imageResource, true);
     //		imagealphablending($imageResource, false);
     $colorId = Dm_Color::argb($backgroundColor)->imagecolorallocatealpha($imageResource);
     //		imagefilledrectangle($imageResource, 0, 0, $width-1, $height-1, $colorId);
     imagefill($imageResource, 0, 0, $colorId);
 }
Ejemplo n.º 2
0
 public function execute(Dm_Image $image)
 {
     $w = $this->width;
     $h = $this->height;
     $x = (int) (($image->getWidth() - $w) * 0.5);
     $y = (int) (($image->getHeight() - $h) * 0.5);
     $resampledResource = imagecreatetruecolor($w, $h);
     //背景色設定(透過を有効化)
     imagesavealpha($resampledResource, true);
     //		imagealphablending($imageResource, false);
     $colorId = Dm_Color::argb(0)->imagecolorallocatealpha($resampledResource);
     //		imagefilledrectangle($imageResource, 0, 0, $width-1, $height-1, $colorId);
     imagefill($resampledResource, 0, 0, $colorId);
     imagecopyresampled($resampledResource, $image->getImageResource(), 0, 0, $x, $y, $image->getWidth(), $image->getHeight(), $image->getWidth(), $image->getHeight());
     return $resampledResource;
 }
Ejemplo n.º 3
0
function draw(&$nodeList, $c)
{
    $image = new Dm_Image(W, H, 0xff000000);
    $graphics = $image->graphics;
    $graphics->lineStyle(0)->fillStyle(0x66ffffff);
    for ($i = 0; $i < C; $i++) {
        $node =& $nodeList[$i];
        $node[2] = 0;
    }
    for ($i = 0; $i < C; $i++) {
        $node =& $nodeList[$i];
        for ($j = $i; $j < C; $j++) {
            if ($i == $j) {
                continue;
            }
            $nNode =& $nodeList[$j];
            $x = $node[0] - $nNode[0];
            $y = $node[1] - $nNode[1];
            $diff = sqrt($x * $x + $y * $y);
            if ($diff < D) {
                $node[2] += 1;
                $nNode[2] += 1;
                $graphics->lineStyle(min(10 * (D - $diff) / D, 4), Dm_Color::argb((D - $diff) / D * 0.6 + 0.2, 255, 255, 255)->toInt())->moveTo($node[0], $node[1])->lineTo($nNode[0], $nNode[1]);
            }
        }
    }
    $graphics->lineStyle(0, 0x11ffffff);
    for ($i = 0; $i < C; $i++) {
        $node = $nodeList[$i];
        $graphics->drawCircle($node[0], $node[1], 2 + $node[2] * $node[2] * 0.2);
    }
    for ($i = 0; $i < C; $i++) {
        $node =& $nodeList[$i];
        $node[0] += $node[3];
        $node[1] += $node[4];
    }
    $count = sprintf('%05d', $c);
    $image->saveTo(DIR_PATH . 'img' . $count . '.gif', 'gif');
}
Ejemplo n.º 4
0
 public function execute(Dm_Image $image)
 {
     $width = $this->width;
     $height = $this->height;
     $ratio = 1;
     $wRatio = $width / $image->getWidth();
     $hRatio = $height / $image->getHeight();
     if ($wRatio > $hRatio) {
         $ratio = $this->bounding ? $wRatio : $hRatio;
     } else {
         $ratio = $this->bounding ? $hRatio : $wRatio;
     }
     $w = $image->getWidth() * $ratio;
     $h = $image->getHeight() * $ratio;
     $resampledResource = imagecreatetruecolor($w, $h);
     //背景色設定(透過を有効化)
     imagesavealpha($resampledResource, true);
     //		imagealphablending($imageResource, false);
     $colorId = Dm_Color::argb(0)->imagecolorallocatealpha($resampledResource);
     //		imagefilledrectangle($imageResource, 0, 0, $width-1, $height-1, $colorId);
     imagefill($resampledResource, 0, 0, $colorId);
     imagecopyresampled($resampledResource, $image->getImageResource(), 0, 0, 0, 0, $w, $h, $image->getWidth(), $image->getHeight());
     return $resampledResource;
 }
Ejemplo n.º 5
0
require_once $DmDirPath.'Dm/Image/Graphic/Shape.php';
require_once $DmDirPath.'Dm/Image/File.php';
require_once $DmDirPath.'Dm/Image/Filter/Abstract.php';
require_once $DmDirPath.'Dm/Image/Filter/Fit.php';
require_once $DmDirPath.'Dm/Image/Filter/Crop.php';
require_once $DmDirPath.'Dm/Image/Filter/InstagramNormal.php';
require_once $DmDirPath.'Dm/Image/Filter/InstagramLoFi.php';
require_once $DmDirPath.'Dm/Image/Filter/InstagramWalden.php';
require_once $DmDirPath.'Dm/Image/Filter/InstagramToaster.php';
*/
//------------------------------------
// エラー出力(ここは必要に応じて)
//------------------------------------
ini_set('display_errors', 'on');
error_reporting(-1);
set_error_handler('onError');
function onError($errno, $errstr, $errfile, $errline)
{
    var_dump($errno, $errstr, $errfile, $errline);
    exit;
}
//------------------------------------
// サンプル
//------------------------------------
$color = Dm_Color::argb(1, 255, 0, 0);
//RGB指定
$color->v *= 0.5;
//明度を半分に(HSV)
$image = new Dm_Image(400, 300, $color->toInt());
$image->display();
exit;
Ejemplo n.º 6
0
 /**
  * 文字列を描画する
  * @param int X軸(px)
  * @param int Y軸(px)
  * @param string 文字列
  * @return Dm_Image_Graphic_Text
  */
 public function textTo($x, $y, $text, $angle = 0)
 {
     imagettftext($this->_imageResource, $this->_fontSize, $angle, $x, $y, Dm_Color::argb($this->_fontColor)->imagecolorallocatealpha($this->_imageResource), $this->_fontPath, $text);
     return $this;
 }
Ejemplo n.º 7
0
define('D', 50);
$image = new Dm_Image(W, H, 0xff000000);
$graphics = $image->graphics;
$graphics->lineStyle(0)->fillStyle(0x66ffffff);
$nodeList = array();
for ($i = 0; $i < C; $i++) {
    $nodeList[] = array(rand(-20, W + 20), rand(-20, H + 20), 0);
}
for ($i = 0; $i < C; $i++) {
    $node =& $nodeList[$i];
    for ($j = $i; $j < C; $j++) {
        if ($i == $j) {
            continue;
        }
        $nNode =& $nodeList[$j];
        $x = $node[0] - $nNode[0];
        $y = $node[1] - $nNode[1];
        $diff = sqrt($x * $x + $y * $y);
        if ($diff < D) {
            $node[2] += 1;
            $nNode[2] += 1;
            $graphics->lineStyle(min(10 * (D - $diff) / D, 4), Dm_Color::argb((D - $diff) / D * 0.6 + 0.2, 255, 255, 255)->toInt())->moveTo($node[0], $node[1])->lineTo($nNode[0], $nNode[1]);
        }
    }
}
$graphics->lineStyle(0, 0x11ffffff);
for ($i = 0; $i < C; $i++) {
    $node = $nodeList[$i];
    $graphics->drawCircle($node[0], $node[1], 2 + $node[2] * $node[2] * 0.3);
}
$image->display();
Ejemplo n.º 8
0
 /**
  * 
  * @param int 色 例:0x00FF99
  * @return Dm_Image_Graphic_Shape
  */
 public function fillStyle($color)
 {
     $this->_fillColor = $color;
     $this->_fillDmColor = Dm_Color::argb($color);
     return $this;
 }