18 declare(strict_types=1);
38 public const ID =
'fit_square';
54 return GDEngine::class;
63 throw new \InvalidArgumentException(
'Invalid definition');
65 $image = $this->
from($stream);
66 if (!is_resource($image) && !$image instanceof \GdImage) {
70 $size = $for_definition->getMaxSize();
72 $cur_width = imagesx($image);
73 $cur_height = imagesy($image);
75 if ($cur_width < $size && $cur_height < $size) {
79 $width_ratio = $size / $cur_width;
80 $height_ratio = $size / $cur_height;
81 $ratio = min($width_ratio, $height_ratio);
83 $new_height = (
int) floor($cur_height * $ratio);
84 $new_width = (
int) floor($cur_width * $ratio);
85 $resized = imagescale(
95 $for_definition->getQuality(),
canHandleDefinition(FlavourDefinition $definition)
Check if a corresponding configuration can be processed by this Machine.
processStream(FileInformation $information, FileStream $stream, FlavourDefinition $for_definition)
persist()
Define whether the generated flavor and the respective streams should be persisted, or whether they should only be generated and used in-memory.
trait GdImageToStreamTrait
dependsOnEngine()
Return the class name of the Engine that is required for this Machine to work.
to(\GdImage $image, ?int $quality=null)
Currently this is the only way to make a FileStream from a GD image resource.
The base interface for all filesystem streams.