Example #1
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;
 }
Example #2
0
 public function execute(Dm_Image $image)
 {
     $w = $this->width;
     $h = $this->height;
     $f = (int) $this->fram;
     $fit = new Dm_Image_Filter_Fit($w, $h, true);
     $crop = new Dm_Image_Filter_Crop($w, $h);
     $filters = array($fit, $crop);
     $image->applyFilters($filters);
     $effectImage = new Dm_Image_File(dirname(__FILE__) . '/img/instagram_effect_01.png');
     $effectImage->applyFilters($filters);
     $image->draw($effectImage, 0, 0, $effectImage->getWidth(), $effectImage->getHeight());
     $filteredResource = $image->getImageResource();
     $this->effect($filteredResource);
     if ($f === 1 || $f === 2 || $f === 3) {
         $frameImage = new Dm_Image_File(dirname(__FILE__) . '/img/frame_' . str_pad($f, 2, '0', STR_PAD_LEFT) . '.png');
         $frameImage->applyFilters($filters);
         $image->draw($frameImage, 0, 0, $frameImage->getWidth(), $frameImage->getHeight());
     }
     $image->setImageResource($filteredResource);
     return $filteredResource;
 }
Example #3
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;
 }
Example #4
0
 /**
  * Copy and merge part of an image
  * @param DmImage
  * @param int x-coordinate of source point.
  * @param int y-coordinate of source point.
  * @param int Source width.
  * @param int Source height.
  * @return bool Returns TRUE on success or FALSE on failure.
  */
 public function draw(Dm_Image $image, $x = 0, $y = 0, $width = null, $height = null)
 {
     $srcImageResource = $image->getImageResource();
     if (is_null($width)) {
         $width = $image->getWidth();
     }
     if (is_null($height)) {
         $height = $image->getHeight();
     }
     return imagecopy($this->getImageResource(), $srcImageResource, $x, $y, 0, 0, $width, $height);
 }