Example #1
0
 /**
  * Write the resource back to it's owner 
  * @param ImageResource $resource
  * @param Segment $segment
  * @throws ImageResourceException when segment's dimensions do not match resource dimensions
  */
 public function writeSegment(ImageResource $resource, Segment $segment)
 {
     if ($resource->getWidth() !== $segment->getWidth() || $resource->getHeight() !== $segment->getHeight()) {
         throw new ImageResourceException("Dimensions of resource and segment differ");
     }
     imagecopy($this->resource->getResource(), $resource->getResource(), $segment->getCoordinate()->getX(), $segment->getCoordinate()->getY(), 0, 0, $segment->getWidth(), $segment->getHeight());
 }
 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $width = $aResource->getWidth();
     $height = $aResource->getHeight();
     $lineRes = imagecreatetruecolor($width, 1);
     $bgc = imagecolorallocatealpha($lineRes, $this->backgroundColor->getRed(), $this->backgroundColor->getGreen(), $this->backgroundColor->getBlue(), $this->backgroundColor->getAlpha());
     // Background color
     imagefilledrectangle($lineRes, 0, 0, $width, 1, $bgc);
     $rotated = $aResource->cloneResource();
     $rotateFilter = new ImageFilterRotate(180, $this->backgroundColor);
     $rotateFilter->applyFilter($rotated);
     $bg = imagecreatetruecolor($width, $this->height);
     imagecopyresampled($bg, $rotated->getResource(), 0, 0, 0, 0, $width, $height, $width, $height);
     $im = $bg;
     $bg = imagecreatetruecolor($width, $this->height);
     for ($x = 0; $x < $width; $x++) {
         imagecopy($bg, $im, $x, 0, $width - $x, 0, 1, $this->height);
     }
     $im = $bg;
     $in = 100 / $this->height;
     for ($i = 0; $i <= $this->height; $i++) {
         imagecopymerge($im, $lineRes, 0, $i, 0, 0, $width, 1, $this->startOpacity);
         if ($this->startOpacity < 100) {
             $this->startOpacity += $in;
         }
     }
     imagecopymerge($im, $lineRes, 0, 0, 0, 0, $width, $this->divLineHeight, 100);
     // Divider
     if ($this->includeOriginal) {
         // we need to include the original
         $mergeWidth = imagesx($im) + $aResource->getWidth();
         $mergeHeight = imagesy($im) + $aResource->getHeight();
         $imMerge = imagecreatetruecolor($width, $mergeHeight);
         imagecopy($imMerge, $aResource->getResource(), 0, 0, 0, 0, $width, $height);
         imagecopy($imMerge, $im, 0, $aResource->getHeight(), 0, 0, $width, $height);
         $aResource->setResource($imMerge);
     } else {
         $aResource->setResource($im);
     }
 }
 /**
  * Tests ImageResource->getY()
  */
 public function testGetHeight()
 {
     $this->assertEquals($this->res->getHeight(), 600, 'Checking height');
 }
 private function calculatePercentage(ImageResource $resource)
 {
     assert($this->isPercentage === true);
     $this->height = $resource->getHeight() / 100 * $this->height;
     $this->width = $resource->getWidth() / 100 * $this->width;
 }