getImageFile() public method

Get image file path.
public getImageFile ( ) : string
return string File path to image.
Exemplo n.º 1
0
 /**
  * Dither by applying a threshold map.
  *
  * @param Image $image
  *
  * @return Image
  */
 private function ordered($image)
 {
     // Localize vars
     $width = $image->getWidth();
     $height = $image->getHeight();
     $old = $image->getCore();
     $new = imagecreatetruecolor($width, $height);
     $thresholdMap = array(array(15, 135, 45, 165), array(195, 75, 225, 105), array(60, 180, 30, 150), array(240, 120, 210, 90));
     for ($y = 0; $y < $height; $y += 1) {
         for ($x = 0; $x < $width; $x += 1) {
             $color = imagecolorat($old, $x, $y);
             $r = $color >> 16 & 0xff;
             $g = $color >> 8 & 0xff;
             $b = $color & 0xff;
             $gray = round($r * 0.3 + $g * 0.59 + $b * 0.11);
             $threshold = $thresholdMap[$x % 4][$y % 4];
             $oldPixel = ($gray + $threshold) / 2;
             if ($oldPixel <= 127) {
                 // Determine if black or white. Also has the benefit of clipping excess value
                 $newPixel = 0;
             } else {
                 $newPixel = 255;
             }
             // Current pixel
             imagesetpixel($new, $x, $y, imagecolorallocate($new, $newPixel, $newPixel, $newPixel));
         }
     }
     imagedestroy($old);
     // Free resource
     // Create new image with updated core
     return new Image($new, $image->getImageFile(), $width, $height, $image->getType());
 }
Exemplo n.º 2
0
 /**
  * Resize helper function.
  *
  * @param Image $image
  * @param int $newWidth
  * @param int $newHeight
  * @param int $targetX
  * @param int $targetY
  * @param int $srcX
  * @param int $srcY
  *
  */
 private function _resize(&$image, $newWidth, $newHeight, $targetX = 0, $targetY = 0, $srcX = 0, $srcY = 0)
 {
     //        $this->_imageCheck();
     if ($image->isAnimated()) {
         // Animated GIF
         $gift = new GifHelper();
         $blocks = $gift->resize($image->getBlocks(), $newWidth, $newHeight);
         // Resize image instance
         $image = new Image($image->getCore(), $image->getImageFile(), $newWidth, $newHeight, $image->getType(), $blocks, true);
     } else {
         // Create blank image
         $newImage = Image::createBlank($newWidth, $newHeight);
         if (ImageType::PNG === $image->getType()) {
             // Preserve PNG transparency
             $newImage->fullAlphaMode(true);
         }
         imagecopyresampled($newImage->getCore(), $image->getCore(), $targetX, $targetY, $srcX, $srcY, $newWidth, $newHeight, $image->getWidth(), $image->getHeight());
         // Free memory of old resource
         imagedestroy($image->getCore());
         // Resize image instance
         $image = new Image($newImage->getCore(), $image->getImageFile(), $newWidth, $newHeight, $image->getType());
     }
 }
Exemplo n.º 3
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function apply($image)
 {
     // Localize vars
     $width = $image->getWidth();
     $height = $image->getHeight();
     $old = $image->getCore();
     $pixels = array();
     $new = imagecreatetruecolor($width, $height);
     for ($y = 0; $y < $height; $y++) {
         for ($x = 0; $x < $width; $x++) {
             // row 0
             if ($x > 0 and $y > 0) {
                 $matrix[0][0] = $this->getColor($old, $pixels, $x - 1, $y - 1);
             } else {
                 $matrix[0][0] = $this->getColor($old, $pixels, $x, $y);
             }
             if ($y > 0) {
                 $matrix[1][0] = $this->getColor($old, $pixels, $x, $y - 1);
             } else {
                 $matrix[1][0] = $this->getColor($old, $pixels, $x, $y);
             }
             if ($x + 1 < $width and $y > 0) {
                 $matrix[2][0] = $this->getColor($old, $pixels, $x + 1, $y - 1);
             } else {
                 $matrix[2][0] = $this->getColor($old, $pixels, $x, $y);
             }
             // row 1
             if ($x > 0) {
                 $matrix[0][1] = $this->getColor($old, $pixels, $x - 1, $y);
             } else {
                 $matrix[0][1] = $this->getColor($old, $pixels, $x, $y);
             }
             if ($x + 1 < $width) {
                 $matrix[2][1] = $this->getColor($old, $pixels, $x + 1, $y);
             } else {
                 $matrix[2][1] = $this->getColor($old, $pixels, $x, $y);
             }
             // row 1
             if ($x > 0 and $y + 1 < $height) {
                 $matrix[0][2] = $this->getColor($old, $pixels, $x - 1, $y + 1);
             } else {
                 $matrix[0][2] = $this->getColor($old, $pixels, $x, $y);
             }
             if ($y + 1 < $height) {
                 $matrix[1][2] = $this->getColor($old, $pixels, $x, $y + 1);
             } else {
                 $matrix[1][2] = $this->getColor($old, $pixels, $x, $y);
             }
             if ($x + 1 < $width and $y + 1 < $height) {
                 $matrix[2][2] = $this->getColor($old, $pixels, $x + 1, $y + 1);
             } else {
                 $matrix[2][2] = $this->getColor($old, $pixels, $x, $y);
             }
             $edge = $this->convolve($matrix);
             $edge = intval($edge / 2);
             if ($edge > 255) {
                 $edge = 255;
             }
             $color = imagecolorallocate($new, $edge, $edge, $edge);
             imagesetpixel($new, $x, $y, $color);
         }
     }
     imagedestroy($old);
     // Free resource
     // Create and return new image with updated core
     return new Image($new, $image->getImageFile(), $width, $height, $image->getType());
 }