19declare(strict_types=1);
39 public const ID =
'fit_square';
55 return GDEngine::class;
64 throw new \InvalidArgumentException(
'Invalid definition');
66 $image = $this->
from($stream);
67 if (!is_resource($image) && !$image instanceof \GdImage) {
71 $size = $for_definition->getMaxSize();
73 $cur_width = imagesx($image);
74 $cur_height = imagesy($image);
76 if ($cur_width < $size && $cur_height < $size) {
80 $width_ratio = $size / $cur_width;
81 $height_ratio = $size / $cur_height;
82 $ratio = min($width_ratio, $height_ratio);
84 $new_height = (
int) floor($cur_height * $ratio);
85 $new_width = (
int) floor($cur_width * $ratio);
86 $resized = imagescale(
96 $for_definition->getQuality(),
103 $for_definition->persist()
canHandleDefinition(FlavourDefinition $definition)
Check if a corresponding configuration can be processed by this Machine.
processStream(FileInformation $information, FileStream $stream, FlavourDefinition $for_definition)
dependsOnEngine()
Return the class name of the Engine that is required for this Machine to work.
A result encapsulates a value or an error and simplifies the handling of those.
The base interface for all filesystem streams.
to(\GdImage $image, ?int $quality=null)
Currently this is the only way to make a FileStream from a GD image resource.
trait GdImageToStreamTrait
if(!file_exists('../ilias.ini.php'))