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 ImageType::*|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 ImageType::*|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 `ImageType::XXX` constant.
274
+ * @param ImageType::* $type
275
+ * @return value-of<self::Formats>
270
276
*/
271
277
public static function typeToExtension (int $ type ): string
272
278
{
@@ -280,6 +286,7 @@ public static function typeToExtension(int $type): string
280
286
281
287
/**
282
288
* Returns the `ImageType::XXX` constant for given file extension.
289
+ * @return ImageType::*
283
290
*/
284
291
public static function extensionToType (string $ extension ): int
285
292
{
@@ -295,6 +302,7 @@ public static function extensionToType(string $extension): int
295
302
296
303
/**
297
304
* Returns the mime type for the given `ImageType::XXX` constant.
305
+ * @param ImageType::* $type
298
306
*/
299
307
public static function typeToMimeType (int $ type ): string
300
308
{
@@ -314,6 +322,7 @@ public function __construct(\GdImage $image)
314
322
315
323
/**
316
324
* Returns image width.
325
+ * @return positive-int
317
326
*/
318
327
public function getWidth (): int
319
328
{
@@ -323,6 +332,7 @@ public function getWidth(): int
323
332
324
333
/**
325
334
* Returns image height.
335
+ * @return positive-int
326
336
*/
327
337
public function getHeight (): int
328
338
{
@@ -351,7 +361,7 @@ public function getImageResource(): \GdImage
351
361
352
362
/**
353
363
* Scales an image. Width and height accept pixels or percent.
354
- * @param self::OrSmaller|self::OrBigger|self::Stretch|self::Cover|self::ShrinkOnly $mode
364
+ * @param int-mask-of< self::OrSmaller|self::OrBigger|self::Stretch|self::Cover|self::ShrinkOnly> $mode
355
365
*/
356
366
public function resize (int |string |null $ width , int |string |null $ height , int $ mode = self ::OrSmaller): static
357
367
{
@@ -388,7 +398,7 @@ public function resize(int|string|null $width, int|string|null $height, int $mod
388
398
389
399
/**
390
400
* 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
401
+ * @param int-mask-of< self::OrSmaller|self::OrBigger|self::Stretch|self::Cover|self::ShrinkOnly> $mode
392
402
*/
393
403
public static function calculateSize (
394
404
int $ srcWidth ,
@@ -534,7 +544,7 @@ public function sharpen(): static
534
544
535
545
/**
536
546
* Puts another image into this image. Left and top accepts pixels or percent.
537
- * @param int $opacity 0..100
547
+ * @param int<0, 100> $opacity 0..100
538
548
*/
539
549
public function place (self $ image , int |string $ left = 0 , int |string $ top = 0 , int $ opacity = 100 ): static
540
550
{
@@ -596,6 +606,7 @@ public function place(self $image, int|string $left = 0, int|string $top = 0, in
596
606
597
607
/**
598
608
* 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).
609
+ * @param ImageType::*|null $type
599
610
* @throws ImageException
600
611
*/
601
612
public function save (string $ file , ?int $ quality = null , ?int $ type = null ): void
@@ -607,6 +618,7 @@ public function save(string $file, ?int $quality = null, ?int $type = null): voi
607
618
608
619
/**
609
620
* 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).
621
+ * @param ImageType::* $type
610
622
*/
611
623
public function toString (int $ type = ImageType::JPEG , ?int $ quality = null ): string
612
624
{
@@ -627,6 +639,7 @@ public function __toString(): string
627
639
628
640
/**
629
641
* 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).
642
+ * @param ImageType::* $type
630
643
* @throws ImageException
631
644
*/
632
645
public function send (int $ type = ImageType::JPEG , ?int $ quality = null ): void
@@ -639,6 +652,7 @@ public function send(int $type = ImageType::JPEG, ?int $quality = null): void
639
652
/**
640
653
* Outputs image to browser or file.
641
654
* @throws ImageException
655
+ * @param ImageType::* $type
642
656
*/
643
657
private function output (int $ type , ?int $ quality , ?string $ file = null ): void
644
658
{
0 commit comments