19 declare(strict_types=1);
37 $this->image_converters =
new Images(
false);
49 string $path_to_original,
50 string $path_to_output,
53 int $image_quality = 75
55 $converter = $this->image_converters->thumbnail(
59 ->withQuality($image_quality)
60 ->withFormat($output_format)
62 return $this->
storeStream($converter, $path_to_output);
74 string $path_to_original,
75 string $path_to_output,
78 int $image_quality = 75
80 $converter = $this->image_converters->croppedSquare(
84 ->withQuality($image_quality)
85 ->withFormat($output_format)
88 return $this->
storeStream($converter, $path_to_output);
100 string $path_to_original,
101 string $path_to_output,
104 int $image_quality = 60
106 $converter = $this->image_converters->resizeByWidth(
109 $this->output_options
110 ->withQuality($image_quality)
111 ->withFormat($output_format)
113 return $this->
storeStream($converter, $path_to_output);
122 string $path_to_original,
123 string $path_to_output,
126 int $image_quality = 60
128 $converter = $this->image_converters->resizeByHeight(
131 $this->output_options
132 ->withQuality($image_quality)
133 ->withFormat($output_format)
135 return $this->
storeStream($converter, $path_to_output);
144 string $path_to_original,
145 string $path_to_output,
148 bool $crop_if_true_and_resize_if_false =
true,
150 int $image_quality = 60
152 $converter = $this->image_converters->resizeToFixedSize(
156 $crop_if_true_and_resize_if_false,
157 $this->output_options
158 ->withQuality($image_quality)
159 ->withFormat($output_format)
161 return $this->
storeStream($converter, $path_to_output);
165 string $path_to_original,
166 string $path_to_output,
167 string $output_format,
171 $converter = $this->image_converters->convertToFormat(
177 return $this->
storeStream($converter, $path_to_output);
182 if (!$converter->
isOK()) {
183 throw $converter->
getThrowableIfAny() ?? new \RuntimeException(
'Could not create requested image');
189 if (file_put_contents($path, $stream->getContents()) ===
false) {
190 throw new \RuntimeException(
'Could not store image');
197 return Streams::ofResource(fopen($path_to_original,
'rb'));
ImageOutputOptions $output_options
Interface Observer Contains several chained tasks and infos about them.
buildStream(string $path_to_original)
convertToFormat(string $path_to_original, string $path_to_output, string $output_format, ?int $width=null, ?int $height=null)
croppedSquare(string $path_to_original, string $path_to_output, int $square_size, string $output_format=ImageOutputOptions::FORMAT_KEEP, int $image_quality=75)
storeStream(ImageConverter $converter, string $path)
resizeByHeight(string $path_to_original, string $path_to_output, int $height, string $output_format=ImageOutputOptions::FORMAT_KEEP, int $image_quality=60)
resizeToFixedSize(string $path_to_original, string $path_to_output, int $width, int $height, bool $crop_if_true_and_resize_if_false=true, string $output_format=ImageOutputOptions::FORMAT_KEEP, int $image_quality=60)
The base interface for all filesystem streams.
resizeByWidth(string $path_to_original, string $path_to_output, int $width, string $output_format=ImageOutputOptions::FORMAT_KEEP, int $image_quality=60)
thumbnail(string $path_to_original, string $path_to_output, int $fit_into_size, string $output_format=ImageOutputOptions::FORMAT_KEEP, int $image_quality=75)