Webiny\Component\Image\ImageLoader::open PHP Method

open() public static method

Creates a new ImageInterface instance from the given image at the provided path.
public static open ( File $image ) : Webiny\Component\Image\ImageInterface
$image Webiny\Component\Storage\File\File Path to an image on the disk.
return Webiny\Component\Image\ImageInterface
    public static function open(File $image)
    {
        $img = self::getLoader()->open($image);
        $img->setDestination($image);
        // extract the format
        $format = self::str($image->getKey())->explode('.')->last()->caseLower()->val();
        $img->setFormat($format);
        // fix image orientation (iPhone/Android issue)
        self::fixImageOrientation($image, $img);
        return $img;
    }

Usage Example

Example #1
0
 public function testOpen()
 {
     // build File mock
     $file = $this->getMockBuilder('\\Webiny\\Component\\Storage\\File\\File')->disableOriginalConstructor()->setMethods(['getAbsolutePath', 'getKey'])->getMock();
     // getAbsolutePath mock
     $file->expects($this->any())->method('getAbsolutePath')->will($this->returnValue(__DIR__ . '/image.gif'));
     // getKey mock
     $file->expects($this->once())->method('getKey')->will($this->returnValue(__DIR__ . '/image.gif'));
     $image = ImageLoader::open($file);
     $this->assertInstanceOf('\\Webiny\\Component\\Image\\ImageInterface', $image);
 }
All Usage Examples Of Webiny\Component\Image\ImageLoader::open