Pop\Image\Imagick::convert PHP Метод

convert() публичный Метод

Convert the image object to the new specified image type.
public convert ( string $type ) : Imagick
$type string
Результат Imagick
    public function convert($type)
    {
        $type = strtolower($type);
        // Check if the requested image type is supported.
        if (!array_key_exists($type, $this->allowed)) {
            throw new Exception('Error: That image type is not supported.');
            // Check if the image is already the requested image type.
        } else {
            if (strtolower($this->ext) == $type) {
                throw new Exception('Error: This image file is already a ' . strtoupper($type) . ' image file.');
            }
        }
        // Else, save the image as the new type.
        $old = $this->ext;
        $this->ext = $type;
        $this->mime = $this->allowed[$this->ext];
        $this->fullpath = $this->dir . $this->filename . '.' . $this->ext;
        $this->basename = basename($this->fullpath);
        if ($old == 'psd' || $old == 'tif' || $old == 'tiff') {
            $this->flatten();
        }
        $this->resource->setImageFormat($type);
        return $this;
    }

Usage Example

Пример #1
0
 public function testConvertExceptionDupeType()
 {
     $this->setExpectedException('Pop\\Image\\Exception');
     $i = new Imagick(__DIR__ . '/../tmp/test.gif');
     $i->convert('gif');
 }