90
90
* @method void stringUp($font, $x, $y, string $s, $col)
91
91
* @method void trueColorToPalette(bool $dither, $ncolors)
92
92
* @method array ttfText($size, $angle, $x, $y, $color, string $fontfile, string $text)
93
- * @property-read int $width
94
- * @property-read int $height
93
+ * @property-read positive- int $width
94
+ * @property-read positive- int $height
95
95
* @property-read \GdImage $imageResource
96
96
*/
97
97
class Image
@@ -220,6 +220,8 @@ private static function invokeSafe(string $func, string $arg, string $message, s
220
220
221
221
/**
222
222
* Creates a new true color image of the given dimensions. The default color is black.
223
+ * @param positive-int $width
224
+ * @param positive-int $height
223
225
* @throws Nette\NotSupportedException if gd extension is not loaded
224
226
*/
225
227
public static function fromBlank (int $ width , int $ height , ?array $ color = null ): static
@@ -247,6 +249,7 @@ public static function fromBlank(int $width, int $height, ?array $color = null):
247
249
248
250
/**
249
251
* Returns the type of image from file.
252
+ * @return self::JPEG|self::PNG|self::GIF|self::WEBP|self::AVIF|self::BMP|null
250
253
*/
251
254
public static function detectTypeFromFile (string $ file , &$ width = null , &$ height = null ): ?int
252
255
{
@@ -257,6 +260,7 @@ public static function detectTypeFromFile(string $file, &$width = null, &$height
257
260
258
261
/**
259
262
* Returns the type of image from string.
263
+ * @return self::JPEG|self::PNG|self::GIF|self::WEBP|self::AVIF|self::BMP|null
260
264
*/
261
265
public static function detectTypeFromString (string $ s , &$ width = null , &$ height = null ): ?int
262
266
{
@@ -267,6 +271,8 @@ public static function detectTypeFromString(string $s, &$width = null, &$height
267
271
268
272
/**
269
273
* Returns the file extension for the given `Image::XXX` constant.
274
+ * @param self::JPEG|self::PNG|self::GIF|self::WEBP|self::AVIF|self::BMP $type
275
+ * @return value-of<self::Formats>
270
276
*/
271
277
public static function typeToExtension (int $ type ): string
272
278
{
@@ -280,6 +286,8 @@ public static function typeToExtension(int $type): string
280
286
281
287
/**
282
288
* Returns the `Image::XXX` constant for given file extension.
289
+ * @param value-of<self::Formats>|'jpg' $extension
290
+ * @return self::JPEG|self::PNG|self::GIF|self::WEBP|self::AVIF|self::BMP
283
291
*/
284
292
public static function extensionToType (string $ extension ): int
285
293
{
@@ -295,6 +303,7 @@ public static function extensionToType(string $extension): int
295
303
296
304
/**
297
305
* Returns the mime type for the given `Image::XXX` constant.
306
+ * @param self::JPEG|self::PNG|self::GIF|self::WEBP|self::AVIF|self::BMP $type
298
307
*/
299
308
public static function typeToMimeType (int $ type ): string
300
309
{
@@ -314,6 +323,7 @@ public function __construct(\GdImage $image)
314
323
315
324
/**
316
325
* Returns image width.
326
+ * @return positive-int
317
327
*/
318
328
public function getWidth (): int
319
329
{
@@ -323,6 +333,7 @@ public function getWidth(): int
323
333
324
334
/**
325
335
* Returns image height.
336
+ * @return positive-int
326
337
*/
327
338
public function getHeight (): int
328
339
{
@@ -351,7 +362,7 @@ public function getImageResource(): \GdImage
351
362
352
363
/**
353
364
* Scales an image. Width and height accept pixels or percent.
354
- * @param self::OrSmaller|self::OrBigger|self::Stretch|self::Cover|self::ShrinkOnly $mode
365
+ * @param int-mask-of< self::OrSmaller|self::OrBigger|self::Stretch|self::Cover|self::ShrinkOnly> $mode
355
366
*/
356
367
public function resize (int |string |null $ width , int |string |null $ height , int $ mode = self ::OrSmaller): static
357
368
{
@@ -388,7 +399,7 @@ public function resize(int|string|null $width, int|string|null $height, int $mod
388
399
389
400
/**
390
401
* Calculates dimensions of resized image. Width and height accept pixels or percent.
391
- * @param self::OrSmaller|self::OrBigger|self::Stretch|self::Cover|self::ShrinkOnly $mode
402
+ * @param int-mask-of< self::OrSmaller|self::OrBigger|self::Stretch|self::Cover|self::ShrinkOnly> $mode
392
403
*/
393
404
public static function calculateSize (
394
405
int $ srcWidth ,
@@ -534,7 +545,7 @@ public function sharpen(): static
534
545
535
546
/**
536
547
* Puts another image into this image. Left and top accepts pixels or percent.
537
- * @param int $opacity 0..100
548
+ * @param int<0, 100> $opacity 0..100
538
549
*/
539
550
public function place (self $ image , int |string $ left = 0 , int |string $ top = 0 , int $ opacity = 100 ): static
540
551
{
@@ -596,6 +607,7 @@ public function place(self $image, int|string $left = 0, int|string $top = 0, in
596
607
597
608
/**
598
609
* Saves image to the file. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
610
+ * @param self::JPEG|self::PNG|self::GIF|self::WEBP|self::AVIF|self::BMP|null $type
599
611
* @throws ImageException
600
612
*/
601
613
public function save (string $ file , ?int $ quality = null , ?int $ type = null ): void
@@ -607,6 +619,7 @@ public function save(string $file, ?int $quality = null, ?int $type = null): voi
607
619
608
620
/**
609
621
* Outputs image to string. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
622
+ * @param self::JPEG|self::PNG|self::GIF|self::WEBP|self::AVIF|self::BMP $type
610
623
*/
611
624
public function toString (int $ type = self ::JPEG , ?int $ quality = null ): string
612
625
{
@@ -627,6 +640,7 @@ public function __toString(): string
627
640
628
641
/**
629
642
* Outputs image to browser. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
643
+ * @param self::JPEG|self::PNG|self::GIF|self::WEBP|self::AVIF|self::BMP $type
630
644
* @throws ImageException
631
645
*/
632
646
public function send (int $ type = self ::JPEG , ?int $ quality = null ): void
@@ -639,6 +653,7 @@ public function send(int $type = self::JPEG, ?int $quality = null): void
639
653
/**
640
654
* Outputs image to browser or file.
641
655
* @throws ImageException
656
+ * @param self::JPEG|self::PNG|self::GIF|self::WEBP|self::AVIF|self::BMP $type
642
657
*/
643
658
private function output (int $ type , ?int $ quality , ?string $ file = null ): void
644
659
{
0 commit comments