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;
}