public function resize($width, $height)
{
$this->preModify();
// this is the check for vector formats because they need to have a resolution set
// this does only work if "resize" is the first step in the image-pipeline
if ($this->isVectorGraphic()) {
// the resolution has to be set before loading the image, that's why we have to destroy the instance and load it again
$res = $this->resource->getImageResolution();
$x_ratio = $res['x'] / $this->getWidth();
$y_ratio = $res['y'] / $this->getHeight();
$this->resource->removeImage();
$newRes = ["x" => $width * $x_ratio, "y" => $height * $y_ratio];
// only use the calculated resolution if we need a higher one that the one we got from the metadata (getImageResolution)
// this is because sometimes the quality is much better when using the "native" resolution from the metadata
if ($newRes["x"] > $res["x"] && $newRes["y"] > $res["y"]) {
$this->resource->setResolution($newRes["x"], $newRes["y"]);
} else {
$this->resource->setResolution($res["x"], $res["y"]);
}
$this->resource->readImage($this->imagePath);
$this->setColorspaceToRGB();
}
$width = (int) $width;
$height = (int) $height;
$this->resource->resizeimage($width, $height, \Imagick::FILTER_UNDEFINED, 1, false);
$this->setWidth($width);
$this->setHeight($height);
$this->postModify();
return $this;
}