public function onSpritesLoaded(Event $event) { foreach ($this->job->sprites as $sprite) { if (!$sprite->enabled) { continue; } $configuration = $this->getSpriteConfiguration($sprite); if (!$configuration->getBool('enabled', true)) { continue; } $scale = $configuration->getTwoSide('scale', 1); if ($scale->sideA != 1 && $scale->sideB != 1) { $image = ImageTools::resizeImage($sprite->image, round($sprite->width * $scale->sideA), round($sprite->height * $scale->sideB), false, ImageTools::MODE_EXACT); $sprite->replaceImage($image); continue; } $width = $configuration->getInt('width'); $height = $configuration->getInt('height'); if (!$width && !$height) { return; } $newWidth = $width; $newHeight = $height; if ($width && $height) { } elseif ($width) { $newHeight = $newWidth / ($sprite->width / $sprite->height); } else { $newWidth = $newHeight * ($sprite->width / $sprite->height); } if ($newWidth != $sprite->width || $newHeight != $sprite->height) { $image = ImageTools::resizeImage($sprite->image, $newWidth, $newHeight, false, ImageTools::MODE_EXACT); $sprite->replaceImage($image); } } }
public function save() { if ($this->_image) { $this->onProcessImage($this->_image); if ($this->_data) { $this->saveFilename = $this->_data; if (!$this->valueContainsExtension) { $this->saveFilename .= '.' . $this->saveFormat; } } else { if (!$this->saveFilename) { $this->_data = FileTools::createUniqueFilename($this->saveDirectory, '.' . $this->saveFormat, 32, true); if ($this->valueContainsExtension) { $this->saveFilename = $this->_data = $this->_data . '.' . $this->saveFormat; } else { $this->saveFilename = $this->_data . '.' . $this->saveFormat; } } } if ($this->resizeToWidth) { $image = ImageTools::resizeImage($this->_image, $this->resizeToWidth, $this->resizeToHeight, false, $this->resizeImageToolsScaleMode, $this->resizeImageToolsBackground); } else { $image = $this->_image; } if ($this->saveFormat == 'jpg') { imagejpeg($image, $this->saveDirectory . $this->saveFilename, $this->saveQuality); } else { if ($this->saveFormat == 'png') { imagepng($image, $this->saveDirectory . $this->saveFilename); } } $this->onImageProcessed($this->_image); if ($image != $this->_image) { imagedestroy($this->_image); } imagedestroy($image); } }