1<?php
2
3namespace Safe;
4
5use Safe\Exceptions\ImageException;
6
7/**
8 * The getimagesize function will determine the
9 * size of any supported given image file and return the dimensions along with
10 * the file type and a height/width text string to be used inside a
11 * normal HTML IMG tag and the
12 * correspondent HTTP content type.
13 *
14 * getimagesize can also return some more information
15 * in imageinfo parameter.
16 *
17 * @param string $filename This parameter specifies the file you wish to retrieve information
18 * about. It can reference a local file or (configuration permitting) a
19 * remote file using one of the supported streams.
20 * @param array $imageinfo This optional parameter allows you to extract some extended
21 * information from the image file. Currently, this will return the
22 * different JPG APP markers as an associative array.
23 * Some programs use these APP markers to embed text information in
24 * images. A very common one is to embed
25 * IPTC information in the APP13 marker.
26 * You can use the iptcparse function to parse the
27 * binary APP13 marker into something readable.
28 *
29 * The imageinfo only supports
30 * JFIF files.
31 * @return array Returns an array with up to 7 elements. Not all image types will include
32 * the channels and bits elements.
33 *
34 * Index 0 and 1 contains respectively the width and the height of the image.
35 *
36 * Index 2 is one of the IMAGETYPE_XXX constants indicating
37 * the type of the image.
38 *
39 * Index 3 is a text string with the correct
40 * height="yyy" width="xxx" string that can be used
41 * directly in an IMG tag.
42 *
43 * mime is the correspondant MIME type of the image.
44 * This information can be used to deliver images with the correct HTTP
45 * Content-type header:
46 *
47 * getimagesize and MIME types
48 *
49 *
50 * ]]>
51 *
52 *
53 *
54 * channels will be 3 for RGB pictures and 4 for CMYK
55 * pictures.
56 *
57 * bits is the number of bits for each color.
58 *
59 * For some image types, the presence of channels and
60 * bits values can be a bit
61 * confusing. As an example, GIF always uses 3 channels
62 * per pixel, but the number of bits per pixel cannot be calculated for an
63 * animated GIF with a global color table.
64 *
65 * On failure, FALSE is returned.
66 * @throws ImageException
67 *
68 */
69function getimagesize(string $filename, array &$imageinfo = null): array
70{
71    error_clear_last();
72    $result = \getimagesize($filename, $imageinfo);
73    if ($result === false) {
74        throw ImageException::createFromPhpError();
75    }
76    return $result;
77}
78
79
80/**
81 * image2wbmp outputs or save a WBMP
82 * version of the given image.
83 *
84 * @param resource $image An image resource, returned by one of the image creation functions,
85 * such as imagecreatetruecolor.
86 * @param string|null $filename Path to the saved file. If not given, the raw image stream will be
87 * output directly.
88 * @param int $foreground You can set the foreground color with this parameter by setting an
89 * identifier obtained from imagecolorallocate.
90 * The default foreground color is black.
91 * @throws ImageException
92 *
93 */
94function image2wbmp($image, ?string $filename = null, int $foreground = null): void
95{
96    error_clear_last();
97    if ($foreground !== null) {
98        $result = \image2wbmp($image, $filename, $foreground);
99    } elseif ($filename !== null) {
100        $result = \image2wbmp($image, $filename);
101    } else {
102        $result = \image2wbmp($image);
103    }
104    if ($result === false) {
105        throw ImageException::createFromPhpError();
106    }
107}
108
109
110/**
111 *
112 *
113 * @param resource $image An image resource, returned by one of the image creation functions,
114 * such as imagecreatetruecolor.
115 * @param array $affine Array with keys 0 to 5.
116 * @param array $clip Array with keys "x", "y", "width" and "height".
117 * @return resource Return affined image resource on success.
118 * @throws ImageException
119 *
120 */
121function imageaffine($image, array $affine, array $clip = null)
122{
123    error_clear_last();
124    if ($clip !== null) {
125        $result = \imageaffine($image, $affine, $clip);
126    } else {
127        $result = \imageaffine($image, $affine);
128    }
129    if ($result === false) {
130        throw ImageException::createFromPhpError();
131    }
132    return $result;
133}
134
135
136/**
137 * Returns the concatenation of two affine transformation matrices,
138 * what is useful if multiple transformations should be applied to the same
139 * image in one go.
140 *
141 * @param array $m1 An affine transformation matrix (an array with keys
142 * 0 to 5 and float values).
143 * @param array $m2 An affine transformation matrix (an array with keys
144 * 0 to 5 and float values).
145 * @return array{0:float,1:float,2:float,3:float,4:float,5:float} An affine transformation matrix (an array with keys
146 * 0 to 5 and float values).
147 * @throws ImageException
148 *
149 */
150function imageaffinematrixconcat(array $m1, array $m2): array
151{
152    error_clear_last();
153    $result = \imageaffinematrixconcat($m1, $m2);
154    if ($result === false) {
155        throw ImageException::createFromPhpError();
156    }
157    return $result;
158}
159
160
161/**
162 * Returns an affine transformation matrix.
163 *
164 * @param int $type One of the IMG_AFFINE_* constants.
165 * @param array|float $options If type is IMG_AFFINE_TRANSLATE
166 * or IMG_AFFINE_SCALE,
167 * options has to be an array with keys x
168 * and y, both having float values.
169 *
170 * If type is IMG_AFFINE_ROTATE,
171 * IMG_AFFINE_SHEAR_HORIZONTAL or IMG_AFFINE_SHEAR_VERTICAL,
172 * options has to be a float specifying the angle.
173 * @return array{0:float,1:float,2:float,3:float,4:float,5:float} An affine transformation matrix (an array with keys
174 * 0 to 5 and float values).
175 * @throws ImageException
176 *
177 */
178function imageaffinematrixget(int $type, $options = null): array
179{
180    error_clear_last();
181    if ($options !== null) {
182        $result = \imageaffinematrixget($type, $options);
183    } else {
184        $result = \imageaffinematrixget($type);
185    }
186    if ($result === false) {
187        throw ImageException::createFromPhpError();
188    }
189    return $result;
190}
191
192
193/**
194 * imagealphablending allows for two different
195 * modes of drawing on truecolor images. In blending mode, the
196 * alpha channel component of the color supplied to all drawing function,
197 * such as imagesetpixel determines how much of the
198 * underlying color should be allowed to shine through.  As a result, gd
199 * automatically blends the existing color at that point with the drawing color,
200 * and stores the result in the image.  The resulting pixel is opaque.  In
201 * non-blending mode, the drawing color is copied literally with its alpha channel
202 * information, replacing the destination pixel.  Blending mode is not available
203 * when drawing on palette images.
204 *
205 * @param resource $image An image resource, returned by one of the image creation functions,
206 * such as imagecreatetruecolor.
207 * @param bool $blendmode Whether to enable the blending mode or not. On true color images
208 * the default value is TRUE otherwise the default value is FALSE
209 * @throws ImageException
210 *
211 */
212function imagealphablending($image, bool $blendmode): void
213{
214    error_clear_last();
215    $result = \imagealphablending($image, $blendmode);
216    if ($result === false) {
217        throw ImageException::createFromPhpError();
218    }
219}
220
221
222/**
223 * Activate the fast drawing antialiased methods for lines and wired polygons.
224 * It does not support alpha components. It works using a direct blend
225 * operation. It works only with truecolor images.
226 *
227 * Thickness and styled are not supported.
228 *
229 * Using antialiased primitives with transparent background color can end with
230 * some unexpected results. The blend method uses the background color as any
231 * other colors. The lack of alpha component support does not allow an alpha
232 * based antialiasing method.
233 *
234 * @param resource $image An image resource, returned by one of the image creation functions,
235 * such as imagecreatetruecolor.
236 * @param bool $enabled Whether to enable antialiasing or not.
237 * @throws ImageException
238 *
239 */
240function imageantialias($image, bool $enabled): void
241{
242    error_clear_last();
243    $result = \imageantialias($image, $enabled);
244    if ($result === false) {
245        throw ImageException::createFromPhpError();
246    }
247}
248
249
250/**
251 * imagearc draws an arc of circle centered at the given
252 * coordinates.
253 *
254 * @param resource $image An image resource, returned by one of the image creation functions,
255 * such as imagecreatetruecolor.
256 * @param int $cx x-coordinate of the center.
257 * @param int $cy y-coordinate of the center.
258 * @param int $width The arc width.
259 * @param int $height The arc height.
260 * @param int $start The arc start angle, in degrees.
261 * @param int $end The arc end angle, in degrees.
262 * 0° is located at the three-o'clock position, and the arc is drawn
263 * clockwise.
264 * @param int $color A color identifier created with imagecolorallocate.
265 * @throws ImageException
266 *
267 */
268function imagearc($image, int $cx, int $cy, int $width, int $height, int $start, int $end, int $color): void
269{
270    error_clear_last();
271    $result = \imagearc($image, $cx, $cy, $width, $height, $start, $end, $color);
272    if ($result === false) {
273        throw ImageException::createFromPhpError();
274    }
275}
276
277
278/**
279 * Outputs or saves a BMP version of the given image.
280 *
281 * @param resource $image An image resource, returned by one of the image creation functions,
282 * such as imagecreatetruecolor.
283 * @param mixed $to The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly.
284 *
285 * NULL is invalid if the compressed arguments is
286 * not used.
287 * @param bool $compressed Whether the BMP should be compressed with run-length encoding (RLE), or not.
288 * @throws ImageException
289 *
290 */
291function imagebmp($image, $to = null, bool $compressed = true): void
292{
293    error_clear_last();
294    $result = \imagebmp($image, $to, $compressed);
295    if ($result === false) {
296        throw ImageException::createFromPhpError();
297    }
298}
299
300
301/**
302 * imagechar draws the first character of
303 * c in the image identified by
304 * image with its upper-left at
305 * x,y (top left is 0,
306 * 0) with the color color.
307 *
308 * @param resource $image An image resource, returned by one of the image creation functions,
309 * such as imagecreatetruecolor.
310 * @param int $font Can be 1, 2, 3, 4, 5 for built-in
311 * fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your
312 * own font identifiers registered with imageloadfont.
313 * @param int $x x-coordinate of the start.
314 * @param int $y y-coordinate of the start.
315 * @param string $c The character to draw.
316 * @param int $color A color identifier created with imagecolorallocate.
317 * @throws ImageException
318 *
319 */
320function imagechar($image, int $font, int $x, int $y, string $c, int $color): void
321{
322    error_clear_last();
323    $result = \imagechar($image, $font, $x, $y, $c, $color);
324    if ($result === false) {
325        throw ImageException::createFromPhpError();
326    }
327}
328
329
330/**
331 * Draws the character c vertically at the specified
332 * coordinate on the given image.
333 *
334 * @param resource $image An image resource, returned by one of the image creation functions,
335 * such as imagecreatetruecolor.
336 * @param int $font Can be 1, 2, 3, 4, 5 for built-in
337 * fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your
338 * own font identifiers registered with imageloadfont.
339 * @param int $x x-coordinate of the start.
340 * @param int $y y-coordinate of the start.
341 * @param string $c The character to draw.
342 * @param int $color A color identifier created with imagecolorallocate.
343 * @throws ImageException
344 *
345 */
346function imagecharup($image, int $font, int $x, int $y, string $c, int $color): void
347{
348    error_clear_last();
349    $result = \imagecharup($image, $font, $x, $y, $c, $color);
350    if ($result === false) {
351        throw ImageException::createFromPhpError();
352    }
353}
354
355
356/**
357 * Returns the index of the color of the pixel at the
358 * specified location in the image specified by image.
359 *
360 * If the image is a
361 * truecolor image, this function returns the RGB value of that pixel as
362 * integer. Use bitshifting and masking to access the distinct red, green and blue
363 * component values:
364 *
365 * @param resource $image An image resource, returned by one of the image creation functions,
366 * such as imagecreatetruecolor.
367 * @param int $x x-coordinate of the point.
368 * @param int $y y-coordinate of the point.
369 * @return int Returns the index of the color.
370 * @throws ImageException
371 *
372 */
373function imagecolorat($image, int $x, int $y): int
374{
375    error_clear_last();
376    $result = \imagecolorat($image, $x, $y);
377    if ($result === false) {
378        throw ImageException::createFromPhpError();
379    }
380    return $result;
381}
382
383
384/**
385 * De-allocates a color previously allocated with
386 * imagecolorallocate or
387 * imagecolorallocatealpha.
388 *
389 * @param resource $image An image resource, returned by one of the image creation functions,
390 * such as imagecreatetruecolor.
391 * @param int $color The color identifier.
392 * @throws ImageException
393 *
394 */
395function imagecolordeallocate($image, int $color): void
396{
397    error_clear_last();
398    $result = \imagecolordeallocate($image, $color);
399    if ($result === false) {
400        throw ImageException::createFromPhpError();
401    }
402}
403
404
405/**
406 * Makes the colors of the palette version of an image more closely match the true color version.
407 *
408 * @param resource $image1 A truecolor image resource.
409 * @param resource $image2 A palette image resource pointing to an image that has the same
410 * size as image1.
411 * @throws ImageException
412 *
413 */
414function imagecolormatch($image1, $image2): void
415{
416    error_clear_last();
417    $result = \imagecolormatch($image1, $image2);
418    if ($result === false) {
419        throw ImageException::createFromPhpError();
420    }
421}
422
423
424/**
425 * Applies a convolution matrix on the image, using the given coefficient and
426 * offset.
427 *
428 * @param resource $image An image resource, returned by one of the image creation functions,
429 * such as imagecreatetruecolor.
430 * @param array $matrix A 3x3 matrix: an array of three arrays of three floats.
431 * @param float $div The divisor of the result of the convolution, used for normalization.
432 * @param float $offset Color offset.
433 * @throws ImageException
434 *
435 */
436function imageconvolution($image, array $matrix, float $div, float $offset): void
437{
438    error_clear_last();
439    $result = \imageconvolution($image, $matrix, $div, $offset);
440    if ($result === false) {
441        throw ImageException::createFromPhpError();
442    }
443}
444
445
446/**
447 * Copy a part of src_im onto
448 * dst_im starting at the x,y coordinates
449 * src_x, src_y  with
450 * a width of src_w and a height of
451 * src_h.  The portion defined will be copied
452 * onto the x,y coordinates, dst_x and
453 * dst_y.
454 *
455 * @param resource $dst_im Destination image resource.
456 * @param resource $src_im Source image resource.
457 * @param int $dst_x x-coordinate of destination point.
458 * @param int $dst_y y-coordinate of destination point.
459 * @param int $src_x x-coordinate of source point.
460 * @param int $src_y y-coordinate of source point.
461 * @param int $src_w Source width.
462 * @param int $src_h Source height.
463 * @throws ImageException
464 *
465 */
466function imagecopy($dst_im, $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h): void
467{
468    error_clear_last();
469    $result = \imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
470    if ($result === false) {
471        throw ImageException::createFromPhpError();
472    }
473}
474
475
476/**
477 * Copy a part of src_im onto
478 * dst_im starting at the x,y coordinates
479 * src_x, src_y  with
480 * a width of src_w and a height of
481 * src_h.  The portion defined will be copied
482 * onto the x,y coordinates, dst_x and
483 * dst_y.
484 *
485 * @param resource $dst_im Destination image resource.
486 * @param resource $src_im Source image resource.
487 * @param int $dst_x x-coordinate of destination point.
488 * @param int $dst_y y-coordinate of destination point.
489 * @param int $src_x x-coordinate of source point.
490 * @param int $src_y y-coordinate of source point.
491 * @param int $src_w Source width.
492 * @param int $src_h Source height.
493 * @param int $pct The two images will be merged according to pct
494 * which can range from 0 to 100.  When pct = 0,
495 * no action is taken, when 100 this function behaves identically
496 * to imagecopy for pallete images, except for
497 * ignoring alpha components, while it implements alpha transparency
498 * for true colour images.
499 * @throws ImageException
500 *
501 */
502function imagecopymerge($dst_im, $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h, int $pct): void
503{
504    error_clear_last();
505    $result = \imagecopymerge($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct);
506    if ($result === false) {
507        throw ImageException::createFromPhpError();
508    }
509}
510
511
512/**
513 * imagecopymergegray copy a part of src_im onto
514 * dst_im starting at the x,y coordinates
515 * src_x, src_y  with
516 * a width of src_w and a height of
517 * src_h.  The portion defined will be copied
518 * onto the x,y coordinates, dst_x and
519 * dst_y.
520 *
521 * This function is identical to imagecopymerge except
522 * that when merging it preserves the hue of the source by converting
523 * the destination pixels to gray scale before the copy operation.
524 *
525 * @param resource $dst_im Destination image resource.
526 * @param resource $src_im Source image resource.
527 * @param int $dst_x x-coordinate of destination point.
528 * @param int $dst_y y-coordinate of destination point.
529 * @param int $src_x x-coordinate of source point.
530 * @param int $src_y y-coordinate of source point.
531 * @param int $src_w Source width.
532 * @param int $src_h Source height.
533 * @param int $pct The src_im will be changed to grayscale according
534 * to pct where 0 is fully grayscale and 100 is
535 * unchanged. When pct = 100 this function behaves
536 * identically to imagecopy for pallete images, except for
537 * ignoring alpha components, while
538 * it implements alpha transparency for true colour images.
539 * @throws ImageException
540 *
541 */
542function imagecopymergegray($dst_im, $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h, int $pct): void
543{
544    error_clear_last();
545    $result = \imagecopymergegray($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct);
546    if ($result === false) {
547        throw ImageException::createFromPhpError();
548    }
549}
550
551
552/**
553 * imagecopyresampled copies a rectangular
554 * portion of one image to another image, smoothly interpolating pixel
555 * values so that, in particular, reducing the size of an image still
556 * retains a great deal of clarity.
557 *
558 * In other words, imagecopyresampled will take a
559 * rectangular area from src_image of width
560 * src_w and height src_h at
561 * position (src_x,src_y)
562 * and place it in a rectangular area of dst_image
563 * of width dst_w and height dst_h
564 * at position (dst_x,dst_y).
565 *
566 * If the source and destination coordinates and width and heights
567 * differ, appropriate stretching or shrinking of the image fragment
568 * will be performed. The coordinates refer to the upper left
569 * corner.  This function can be used to copy regions within the
570 * same image (if dst_image is the same as
571 * src_image) but if the regions overlap the
572 * results will be unpredictable.
573 *
574 * @param resource $dst_image Destination image resource.
575 * @param resource $src_image Source image resource.
576 * @param int $dst_x x-coordinate of destination point.
577 * @param int $dst_y y-coordinate of destination point.
578 * @param int $src_x x-coordinate of source point.
579 * @param int $src_y y-coordinate of source point.
580 * @param int $dst_w Destination width.
581 * @param int $dst_h Destination height.
582 * @param int $src_w Source width.
583 * @param int $src_h Source height.
584 * @throws ImageException
585 *
586 */
587function imagecopyresampled($dst_image, $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_w, int $dst_h, int $src_w, int $src_h): void
588{
589    error_clear_last();
590    $result = \imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
591    if ($result === false) {
592        throw ImageException::createFromPhpError();
593    }
594}
595
596
597/**
598 * imagecopyresized copies a rectangular
599 * portion of one image to another image.
600 * dst_image is the destination image,
601 * src_image is the source image identifier.
602 *
603 * In other words, imagecopyresized will take a
604 * rectangular area from src_image of width
605 * src_w and height src_h at
606 * position (src_x,src_y)
607 * and place it in a rectangular area of dst_image
608 * of width dst_w and height dst_h
609 * at position (dst_x,dst_y).
610 *
611 * If the source and destination coordinates and width and heights
612 * differ, appropriate stretching or shrinking of the image fragment
613 * will be performed. The coordinates refer to the upper left
614 * corner. This function can be used to copy regions within the
615 * same image (if dst_image is the same as
616 * src_image) but if the regions overlap the
617 * results will be unpredictable.
618 *
619 * @param resource $dst_image Destination image resource.
620 * @param resource $src_image Source image resource.
621 * @param int $dst_x x-coordinate of destination point.
622 * @param int $dst_y y-coordinate of destination point.
623 * @param int $src_x x-coordinate of source point.
624 * @param int $src_y y-coordinate of source point.
625 * @param int $dst_w Destination width.
626 * @param int $dst_h Destination height.
627 * @param int $src_w Source width.
628 * @param int $src_h Source height.
629 * @throws ImageException
630 *
631 */
632function imagecopyresized($dst_image, $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_w, int $dst_h, int $src_w, int $src_h): void
633{
634    error_clear_last();
635    $result = \imagecopyresized($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
636    if ($result === false) {
637        throw ImageException::createFromPhpError();
638    }
639}
640
641
642/**
643 * imagecreate returns an image identifier
644 * representing a blank image of specified size.
645 *
646 * In general, we recommend the use of
647 * imagecreatetruecolor instead of
648 * imagecreate so that image processing occurs on the
649 * highest quality image possible. If you want to output a palette image, then
650 * imagetruecolortopalette should be called immediately
651 * before saving the image with imagepng or
652 * imagegif.
653 *
654 * @param int $width The image width.
655 * @param int $height The image height.
656 * @return resource Returns an image resource identifier on success, FALSE on errors.
657 * @throws ImageException
658 *
659 */
660function imagecreate(int $width, int $height)
661{
662    error_clear_last();
663    $result = \imagecreate($width, $height);
664    if ($result === false) {
665        throw ImageException::createFromPhpError();
666    }
667    return $result;
668}
669
670
671/**
672 * imagecreatefrombmp returns an image identifier
673 * representing the image obtained from the given filename.
674 *
675 * @param string $filename Path to the BMP image.
676 * @return resource Returns an image resource identifier on success, FALSE on errors.
677 * @throws ImageException
678 *
679 */
680function imagecreatefrombmp(string $filename)
681{
682    error_clear_last();
683    $result = \imagecreatefrombmp($filename);
684    if ($result === false) {
685        throw ImageException::createFromPhpError();
686    }
687    return $result;
688}
689
690
691/**
692 * Create a new image from GD file or URL.
693 *
694 * @param string $filename Path to the GD file.
695 * @return resource Returns an image resource identifier on success, FALSE on errors.
696 * @throws ImageException
697 *
698 */
699function imagecreatefromgd(string $filename)
700{
701    error_clear_last();
702    $result = \imagecreatefromgd($filename);
703    if ($result === false) {
704        throw ImageException::createFromPhpError();
705    }
706    return $result;
707}
708
709
710/**
711 * Create a new image from GD2 file or URL.
712 *
713 * @param string $filename Path to the GD2 image.
714 * @return resource Returns an image resource identifier on success, FALSE on errors.
715 * @throws ImageException
716 *
717 */
718function imagecreatefromgd2(string $filename)
719{
720    error_clear_last();
721    $result = \imagecreatefromgd2($filename);
722    if ($result === false) {
723        throw ImageException::createFromPhpError();
724    }
725    return $result;
726}
727
728
729/**
730 * Create a new image from a given part of GD2 file or URL.
731 *
732 * @param string $filename Path to the GD2 image.
733 * @param int $srcX x-coordinate of source point.
734 * @param int $srcY y-coordinate of source point.
735 * @param int $width Source width.
736 * @param int $height Source height.
737 * @return resource Returns an image resource identifier on success, FALSE on errors.
738 * @throws ImageException
739 *
740 */
741function imagecreatefromgd2part(string $filename, int $srcX, int $srcY, int $width, int $height)
742{
743    error_clear_last();
744    $result = \imagecreatefromgd2part($filename, $srcX, $srcY, $width, $height);
745    if ($result === false) {
746        throw ImageException::createFromPhpError();
747    }
748    return $result;
749}
750
751
752/**
753 * imagecreatefromgif returns an image identifier
754 * representing the image obtained from the given filename.
755 *
756 * @param string $filename Path to the GIF image.
757 * @return resource Returns an image resource identifier on success, FALSE on errors.
758 * @throws ImageException
759 *
760 */
761function imagecreatefromgif(string $filename)
762{
763    error_clear_last();
764    $result = \imagecreatefromgif($filename);
765    if ($result === false) {
766        throw ImageException::createFromPhpError();
767    }
768    return $result;
769}
770
771
772/**
773 * imagecreatefromjpeg returns an image identifier
774 * representing the image obtained from the given filename.
775 *
776 * @param string $filename Path to the JPEG image.
777 * @return resource Returns an image resource identifier on success, FALSE on errors.
778 * @throws ImageException
779 *
780 */
781function imagecreatefromjpeg(string $filename)
782{
783    error_clear_last();
784    $result = \imagecreatefromjpeg($filename);
785    if ($result === false) {
786        throw ImageException::createFromPhpError();
787    }
788    return $result;
789}
790
791
792/**
793 * imagecreatefrompng returns an image identifier
794 * representing the image obtained from the given filename.
795 *
796 * @param string $filename Path to the PNG image.
797 * @return resource Returns an image resource identifier on success, FALSE on errors.
798 * @throws ImageException
799 *
800 */
801function imagecreatefrompng(string $filename)
802{
803    error_clear_last();
804    $result = \imagecreatefrompng($filename);
805    if ($result === false) {
806        throw ImageException::createFromPhpError();
807    }
808    return $result;
809}
810
811
812/**
813 * imagecreatefromwbmp returns an image identifier
814 * representing the image obtained from the given filename.
815 *
816 * @param string $filename Path to the WBMP image.
817 * @return resource Returns an image resource identifier on success, FALSE on errors.
818 * @throws ImageException
819 *
820 */
821function imagecreatefromwbmp(string $filename)
822{
823    error_clear_last();
824    $result = \imagecreatefromwbmp($filename);
825    if ($result === false) {
826        throw ImageException::createFromPhpError();
827    }
828    return $result;
829}
830
831
832/**
833 * imagecreatefromwebp returns an image identifier
834 * representing the image obtained from the given filename.
835 *
836 * @param string $filename Path to the WebP image.
837 * @return resource Returns an image resource identifier on success, FALSE on errors.
838 * @throws ImageException
839 *
840 */
841function imagecreatefromwebp(string $filename)
842{
843    error_clear_last();
844    $result = \imagecreatefromwebp($filename);
845    if ($result === false) {
846        throw ImageException::createFromPhpError();
847    }
848    return $result;
849}
850
851
852/**
853 * imagecreatefromxbm returns an image identifier
854 * representing the image obtained from the given filename.
855 *
856 * @param string $filename Path to the XBM image.
857 * @return resource Returns an image resource identifier on success, FALSE on errors.
858 * @throws ImageException
859 *
860 */
861function imagecreatefromxbm(string $filename)
862{
863    error_clear_last();
864    $result = \imagecreatefromxbm($filename);
865    if ($result === false) {
866        throw ImageException::createFromPhpError();
867    }
868    return $result;
869}
870
871
872/**
873 * imagecreatefromxpm returns an image identifier
874 * representing the image obtained from the given filename.
875 *
876 * @param string $filename Path to the XPM image.
877 * @return resource Returns an image resource identifier on success, FALSE on errors.
878 * @throws ImageException
879 *
880 */
881function imagecreatefromxpm(string $filename)
882{
883    error_clear_last();
884    $result = \imagecreatefromxpm($filename);
885    if ($result === false) {
886        throw ImageException::createFromPhpError();
887    }
888    return $result;
889}
890
891
892/**
893 * imagecreatetruecolor returns an image identifier
894 * representing a black image of the specified size.
895 *
896 * @param int $width Image width.
897 * @param int $height Image height.
898 * @return resource Returns an image resource identifier on success, FALSE on errors.
899 * @throws ImageException
900 *
901 */
902function imagecreatetruecolor(int $width, int $height)
903{
904    error_clear_last();
905    $result = \imagecreatetruecolor($width, $height);
906    if ($result === false) {
907        throw ImageException::createFromPhpError();
908    }
909    return $result;
910}
911
912
913/**
914 * Crops an image to the given rectangular area and returns the resulting image.
915 * The given image is not modified.
916 *
917 * @param resource $image An image resource, returned by one of the image creation functions,
918 * such as imagecreatetruecolor.
919 * @param array $rect The cropping rectangle as array with keys
920 * x, y, width and
921 * height.
922 * @return resource Return cropped image resource on success.
923 * @throws ImageException
924 *
925 */
926function imagecrop($image, array $rect)
927{
928    error_clear_last();
929    $result = \imagecrop($image, $rect);
930    if ($result === false) {
931        throw ImageException::createFromPhpError();
932    }
933    return $result;
934}
935
936
937/**
938 * Automatically crops an image according to the given
939 * mode.
940 *
941 * @param resource $image An image resource, returned by one of the image creation functions,
942 * such as imagecreatetruecolor.
943 * @param int $mode One of the following constants:
944 * @param float $threshold
945 * @param int $color
946 * @return resource Returns a cropped image resource on success.
947 * If the complete image was cropped, imagecrop returns FALSE.
948 * @throws ImageException
949 *
950 */
951function imagecropauto($image, int $mode = IMG_CROP_DEFAULT, float $threshold = .5, int $color = -1)
952{
953    error_clear_last();
954    $result = \imagecropauto($image, $mode, $threshold, $color);
955    if ($result === false) {
956        throw ImageException::createFromPhpError();
957    }
958    return $result;
959}
960
961
962/**
963 * This function is deprecated. Use combination of
964 * imagesetstyle and imageline
965 * instead.
966 *
967 * @param resource $image An image resource, returned by one of the image creation functions,
968 * such as imagecreatetruecolor.
969 * @param int $x1 Upper left x coordinate.
970 * @param int $y1 Upper left y coordinate 0, 0 is the top left corner of the image.
971 * @param int $x2 Bottom right x coordinate.
972 * @param int $y2 Bottom right y coordinate.
973 * @param int $color The fill color. A color identifier created with imagecolorallocate.
974 * @throws ImageException
975 *
976 */
977function imagedashedline($image, int $x1, int $y1, int $x2, int $y2, int $color): void
978{
979    error_clear_last();
980    $result = \imagedashedline($image, $x1, $y1, $x2, $y2, $color);
981    if ($result === false) {
982        throw ImageException::createFromPhpError();
983    }
984}
985
986
987/**
988 * imagedestroy frees any memory associated
989 * with image image.
990 *
991 * @param resource $image An image resource, returned by one of the image creation functions,
992 * such as imagecreatetruecolor.
993 * @throws ImageException
994 *
995 */
996function imagedestroy($image): void
997{
998    error_clear_last();
999    $result = \imagedestroy($image);
1000    if ($result === false) {
1001        throw ImageException::createFromPhpError();
1002    }
1003}
1004
1005
1006/**
1007 * Draws an ellipse centered at the specified coordinates.
1008 *
1009 * @param resource $image An image resource, returned by one of the image creation functions,
1010 * such as imagecreatetruecolor.
1011 * @param int $cx x-coordinate of the center.
1012 * @param int $cy y-coordinate of the center.
1013 * @param int $width The ellipse width.
1014 * @param int $height The ellipse height.
1015 * @param int $color The color of the ellipse. A color identifier created with imagecolorallocate.
1016 * @throws ImageException
1017 *
1018 */
1019function imageellipse($image, int $cx, int $cy, int $width, int $height, int $color): void
1020{
1021    error_clear_last();
1022    $result = \imageellipse($image, $cx, $cy, $width, $height, $color);
1023    if ($result === false) {
1024        throw ImageException::createFromPhpError();
1025    }
1026}
1027
1028
1029/**
1030 * Performs a flood fill starting at the given coordinate (top left is 0, 0)
1031 * with the given color in the
1032 * image.
1033 *
1034 * @param resource $image An image resource, returned by one of the image creation functions,
1035 * such as imagecreatetruecolor.
1036 * @param int $x x-coordinate of start point.
1037 * @param int $y y-coordinate of start point.
1038 * @param int $color The fill color. A color identifier created with imagecolorallocate.
1039 * @throws ImageException
1040 *
1041 */
1042function imagefill($image, int $x, int $y, int $color): void
1043{
1044    error_clear_last();
1045    $result = \imagefill($image, $x, $y, $color);
1046    if ($result === false) {
1047        throw ImageException::createFromPhpError();
1048    }
1049}
1050
1051
1052/**
1053 * Draws a partial arc centered at the specified coordinate in the
1054 * given image.
1055 *
1056 * @param resource $image An image resource, returned by one of the image creation functions,
1057 * such as imagecreatetruecolor.
1058 * @param int $cx x-coordinate of the center.
1059 * @param int $cy y-coordinate of the center.
1060 * @param int $width The arc width.
1061 * @param int $height The arc height.
1062 * @param int $start The arc start angle, in degrees.
1063 * @param int $end The arc end angle, in degrees.
1064 * 0° is located at the three-o'clock position, and the arc is drawn
1065 * clockwise.
1066 * @param int $color A color identifier created with imagecolorallocate.
1067 * @param int $style A bitwise OR of the following possibilities:
1068 *
1069 * IMG_ARC_PIE
1070 * IMG_ARC_CHORD
1071 * IMG_ARC_NOFILL
1072 * IMG_ARC_EDGED
1073 *
1074 * IMG_ARC_PIE and IMG_ARC_CHORD are
1075 * mutually exclusive; IMG_ARC_CHORD just
1076 * connects the starting and ending angles with a straight line, while
1077 * IMG_ARC_PIE produces a rounded edge.
1078 * IMG_ARC_NOFILL indicates that the arc
1079 * or chord should be outlined, not filled.  IMG_ARC_EDGED,
1080 * used together with IMG_ARC_NOFILL, indicates that the
1081 * beginning and ending angles should be connected to the center - this is a
1082 * good way to outline (rather than fill) a 'pie slice'.
1083 * @throws ImageException
1084 *
1085 */
1086function imagefilledarc($image, int $cx, int $cy, int $width, int $height, int $start, int $end, int $color, int $style): void
1087{
1088    error_clear_last();
1089    $result = \imagefilledarc($image, $cx, $cy, $width, $height, $start, $end, $color, $style);
1090    if ($result === false) {
1091        throw ImageException::createFromPhpError();
1092    }
1093}
1094
1095
1096/**
1097 * Draws an ellipse centered at the specified coordinate on the given
1098 * image.
1099 *
1100 * @param resource $image An image resource, returned by one of the image creation functions,
1101 * such as imagecreatetruecolor.
1102 * @param int $cx x-coordinate of the center.
1103 * @param int $cy y-coordinate of the center.
1104 * @param int $width The ellipse width.
1105 * @param int $height The ellipse height.
1106 * @param int $color The fill color. A color identifier created with imagecolorallocate.
1107 * @throws ImageException
1108 *
1109 */
1110function imagefilledellipse($image, int $cx, int $cy, int $width, int $height, int $color): void
1111{
1112    error_clear_last();
1113    $result = \imagefilledellipse($image, $cx, $cy, $width, $height, $color);
1114    if ($result === false) {
1115        throw ImageException::createFromPhpError();
1116    }
1117}
1118
1119
1120/**
1121 * imagefilledpolygon creates a filled polygon
1122 * in the given image.
1123 *
1124 * @param resource $image An image resource, returned by one of the image creation functions,
1125 * such as imagecreatetruecolor.
1126 * @param array $points An array containing the x and y
1127 * coordinates of the polygons vertices consecutively.
1128 * @param int $num_points Total number of points (vertices), which must be at least 3.
1129 * @param int $color A color identifier created with imagecolorallocate.
1130 * @throws ImageException
1131 *
1132 */
1133function imagefilledpolygon($image, array $points, int $num_points, int $color): void
1134{
1135    error_clear_last();
1136    $result = \imagefilledpolygon($image, $points, $num_points, $color);
1137    if ($result === false) {
1138        throw ImageException::createFromPhpError();
1139    }
1140}
1141
1142
1143/**
1144 * Creates a rectangle filled with color in the given
1145 * image starting at point 1 and ending at point 2.
1146 * 0, 0 is the top left corner of the image.
1147 *
1148 * @param resource $image An image resource, returned by one of the image creation functions,
1149 * such as imagecreatetruecolor.
1150 * @param int $x1 x-coordinate for point 1.
1151 * @param int $y1 y-coordinate for point 1.
1152 * @param int $x2 x-coordinate for point 2.
1153 * @param int $y2 y-coordinate for point 2.
1154 * @param int $color The fill color. A color identifier created with imagecolorallocate.
1155 * @throws ImageException
1156 *
1157 */
1158function imagefilledrectangle($image, int $x1, int $y1, int $x2, int $y2, int $color): void
1159{
1160    error_clear_last();
1161    $result = \imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
1162    if ($result === false) {
1163        throw ImageException::createFromPhpError();
1164    }
1165}
1166
1167
1168/**
1169 * imagefilltoborder performs a flood fill
1170 * whose border color is defined by border.
1171 * The starting point for the fill is x,
1172 * y (top left is 0, 0) and the region is
1173 * filled with color color.
1174 *
1175 * @param resource $image An image resource, returned by one of the image creation functions,
1176 * such as imagecreatetruecolor.
1177 * @param int $x x-coordinate of start.
1178 * @param int $y y-coordinate of start.
1179 * @param int $border The border color. A color identifier created with imagecolorallocate.
1180 * @param int $color The fill color. A color identifier created with imagecolorallocate.
1181 * @throws ImageException
1182 *
1183 */
1184function imagefilltoborder($image, int $x, int $y, int $border, int $color): void
1185{
1186    error_clear_last();
1187    $result = \imagefilltoborder($image, $x, $y, $border, $color);
1188    if ($result === false) {
1189        throw ImageException::createFromPhpError();
1190    }
1191}
1192
1193
1194/**
1195 * imagefilter applies the given filter
1196 * filtertype on the image.
1197 *
1198 * @param resource $image An image resource, returned by one of the image creation functions,
1199 * such as imagecreatetruecolor.
1200 * @param int $filtertype filtertype can be one of the following:
1201 *
1202 *
1203 *
1204 * IMG_FILTER_NEGATE: Reverses all colors of
1205 * the image.
1206 *
1207 *
1208 *
1209 *
1210 * IMG_FILTER_GRAYSCALE: Converts the image into
1211 * grayscale by changing the red, green and blue components to their
1212 * weighted sum using the same coefficients as the REC.601 luma (Y')
1213 * calculation. The alpha components are retained. For palette images the
1214 * result may differ due to palette limitations.
1215 *
1216 *
1217 *
1218 *
1219 * IMG_FILTER_BRIGHTNESS: Changes the brightness
1220 * of the image. Use arg1 to set the level of
1221 * brightness. The range for the brightness is -255 to 255.
1222 *
1223 *
1224 *
1225 *
1226 * IMG_FILTER_CONTRAST: Changes the contrast of
1227 * the image. Use arg1 to set the level of
1228 * contrast.
1229 *
1230 *
1231 *
1232 *
1233 * IMG_FILTER_COLORIZE: Like
1234 * IMG_FILTER_GRAYSCALE, except you can specify the
1235 * color. Use arg1, arg2 and
1236 * arg3 in the form of
1237 * red, green,
1238 * blue and arg4 for the
1239 * alpha channel. The range for each color is 0 to 255.
1240 *
1241 *
1242 *
1243 *
1244 * IMG_FILTER_EDGEDETECT: Uses edge detection to
1245 * highlight the edges in the image.
1246 *
1247 *
1248 *
1249 *
1250 * IMG_FILTER_EMBOSS: Embosses the image.
1251 *
1252 *
1253 *
1254 *
1255 * IMG_FILTER_GAUSSIAN_BLUR: Blurs the image using
1256 * the Gaussian method.
1257 *
1258 *
1259 *
1260 *
1261 * IMG_FILTER_SELECTIVE_BLUR: Blurs the image.
1262 *
1263 *
1264 *
1265 *
1266 * IMG_FILTER_MEAN_REMOVAL: Uses mean removal to
1267 * achieve a "sketchy" effect.
1268 *
1269 *
1270 *
1271 *
1272 * IMG_FILTER_SMOOTH: Makes the image smoother.
1273 * Use arg1 to set the level of smoothness.
1274 *
1275 *
1276 *
1277 *
1278 * IMG_FILTER_PIXELATE: Applies pixelation effect
1279 * to the image, use arg1 to set the block size
1280 * and arg2 to set the pixelation effect mode.
1281 *
1282 *
1283 *
1284 *
1285 * IMG_FILTER_SCATTER: Applies scatter effect
1286 * to the image, use arg1 and
1287 * arg2 to define the effect strength and
1288 * additionally arg3 to only apply the
1289 * on select pixel colors.
1290 *
1291 *
1292 *
1293 * @param int $arg1
1294 *
1295 *
1296 * IMG_FILTER_BRIGHTNESS: Brightness level.
1297 *
1298 *
1299 *
1300 *
1301 * IMG_FILTER_CONTRAST: Contrast level.
1302 *
1303 *
1304 *
1305 *
1306 * IMG_FILTER_COLORIZE: Value of red component.
1307 *
1308 *
1309 *
1310 *
1311 * IMG_FILTER_SMOOTH: Smoothness level.
1312 *
1313 *
1314 *
1315 *
1316 * IMG_FILTER_PIXELATE: Block size in pixels.
1317 *
1318 *
1319 *
1320 *
1321 * IMG_FILTER_SCATTER: Effect substraction level.
1322 * This must not be higher or equal to the addition level set with
1323 * arg2.
1324 *
1325 *
1326 *
1327 * @param int $arg2
1328 *
1329 *
1330 * IMG_FILTER_COLORIZE: Value of green component.
1331 *
1332 *
1333 *
1334 *
1335 * IMG_FILTER_PIXELATE: Whether to use advanced pixelation
1336 * effect or not (defaults to FALSE).
1337 *
1338 *
1339 *
1340 *
1341 * IMG_FILTER_SCATTER: Effect addition level.
1342 *
1343 *
1344 *
1345 * @param int $arg3
1346 *
1347 *
1348 * IMG_FILTER_COLORIZE: Value of blue component.
1349 *
1350 *
1351 *
1352 *
1353 * IMG_FILTER_SCATTER: Optional array indexed color values
1354 * to apply effect at.
1355 *
1356 *
1357 *
1358 * @param int $arg4
1359 *
1360 *
1361 * IMG_FILTER_COLORIZE: Alpha channel, A value
1362 * between 0 and 127. 0 indicates completely opaque while 127 indicates
1363 * completely transparent.
1364 *
1365 *
1366 *
1367 * @throws ImageException
1368 *
1369 */
1370function imagefilter($image, int $filtertype, int $arg1 = null, int $arg2 = null, int $arg3 = null, int $arg4 = null): void
1371{
1372    error_clear_last();
1373    if ($arg4 !== null) {
1374        $result = \imagefilter($image, $filtertype, $arg1, $arg2, $arg3, $arg4);
1375    } elseif ($arg3 !== null) {
1376        $result = \imagefilter($image, $filtertype, $arg1, $arg2, $arg3);
1377    } elseif ($arg2 !== null) {
1378        $result = \imagefilter($image, $filtertype, $arg1, $arg2);
1379    } elseif ($arg1 !== null) {
1380        $result = \imagefilter($image, $filtertype, $arg1);
1381    } else {
1382        $result = \imagefilter($image, $filtertype);
1383    }
1384    if ($result === false) {
1385        throw ImageException::createFromPhpError();
1386    }
1387}
1388
1389
1390/**
1391 * Flips the image image using the given
1392 * mode.
1393 *
1394 * @param resource $image An image resource, returned by one of the image creation functions,
1395 * such as imagecreatetruecolor.
1396 * @param int $mode Flip mode, this can be one of the IMG_FLIP_* constants:
1397 *
1398 *
1399 *
1400 *
1401 *
1402 * Constant
1403 * Meaning
1404 *
1405 *
1406 *
1407 *
1408 * IMG_FLIP_HORIZONTAL
1409 *
1410 * Flips the image horizontally.
1411 *
1412 *
1413 *
1414 * IMG_FLIP_VERTICAL
1415 *
1416 * Flips the image vertically.
1417 *
1418 *
1419 *
1420 * IMG_FLIP_BOTH
1421 *
1422 * Flips the image both horizontally and vertically.
1423 *
1424 *
1425 *
1426 *
1427 *
1428 * @throws ImageException
1429 *
1430 */
1431function imageflip($image, int $mode): void
1432{
1433    error_clear_last();
1434    $result = \imageflip($image, $mode);
1435    if ($result === false) {
1436        throw ImageException::createFromPhpError();
1437    }
1438}
1439
1440
1441/**
1442 * Applies gamma correction to the given gd image
1443 * given an input and an output gamma.
1444 *
1445 * @param resource $image An image resource, returned by one of the image creation functions,
1446 * such as imagecreatetruecolor.
1447 * @param float $inputgamma The input gamma.
1448 * @param float $outputgamma The output gamma.
1449 * @throws ImageException
1450 *
1451 */
1452function imagegammacorrect($image, float $inputgamma, float $outputgamma): void
1453{
1454    error_clear_last();
1455    $result = \imagegammacorrect($image, $inputgamma, $outputgamma);
1456    if ($result === false) {
1457        throw ImageException::createFromPhpError();
1458    }
1459}
1460
1461
1462/**
1463 * Outputs a GD image to the given to.
1464 *
1465 * @param resource $image An image resource, returned by one of the image creation functions,
1466 * such as imagecreatetruecolor.
1467 * @param mixed $to The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly.
1468 * @throws ImageException
1469 *
1470 */
1471function imagegd($image, $to = null): void
1472{
1473    error_clear_last();
1474    $result = \imagegd($image, $to);
1475    if ($result === false) {
1476        throw ImageException::createFromPhpError();
1477    }
1478}
1479
1480
1481/**
1482 * Outputs a GD2 image to the given to.
1483 *
1484 * @param resource $image An image resource, returned by one of the image creation functions,
1485 * such as imagecreatetruecolor.
1486 * @param mixed $to The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly.
1487 * @param int $chunk_size Chunk size.
1488 * @param int $type Either IMG_GD2_RAW or
1489 * IMG_GD2_COMPRESSED. Default is
1490 * IMG_GD2_RAW.
1491 * @throws ImageException
1492 *
1493 */
1494function imagegd2($image, $to = null, int $chunk_size = 128, int $type = IMG_GD2_RAW): void
1495{
1496    error_clear_last();
1497    $result = \imagegd2($image, $to, $chunk_size, $type);
1498    if ($result === false) {
1499        throw ImageException::createFromPhpError();
1500    }
1501}
1502
1503
1504/**
1505 * imagegif creates the GIF
1506 * file in to from the image image. The
1507 * image argument is the return from the
1508 * imagecreate or imagecreatefrom*
1509 * function.
1510 *
1511 * The image format will be GIF87a unless the
1512 * image has been made transparent with
1513 * imagecolortransparent, in which case the
1514 * image format will be GIF89a.
1515 *
1516 * @param resource $image An image resource, returned by one of the image creation functions,
1517 * such as imagecreatetruecolor.
1518 * @param mixed $to The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly.
1519 * @throws ImageException
1520 *
1521 */
1522function imagegif($image, $to = null): void
1523{
1524    error_clear_last();
1525    $result = \imagegif($image, $to);
1526    if ($result === false) {
1527        throw ImageException::createFromPhpError();
1528    }
1529}
1530
1531
1532/**
1533 * Grabs a screenshot of the whole screen.
1534 *
1535 * @return resource Returns an image resource identifier on success, FALSE on failure.
1536 * @throws ImageException
1537 *
1538 */
1539function imagegrabscreen()
1540{
1541    error_clear_last();
1542    $result = \imagegrabscreen();
1543    if ($result === false) {
1544        throw ImageException::createFromPhpError();
1545    }
1546    return $result;
1547}
1548
1549
1550/**
1551 * Grabs a window or its client area using a windows handle (HWND property in COM instance)
1552 *
1553 * @param int $window_handle The HWND window ID.
1554 * @param int $client_area Include the client area of the application window.
1555 * @return resource Returns an image resource identifier on success, FALSE on failure.
1556 * @throws ImageException
1557 *
1558 */
1559function imagegrabwindow(int $window_handle, int $client_area = 0)
1560{
1561    error_clear_last();
1562    $result = \imagegrabwindow($window_handle, $client_area);
1563    if ($result === false) {
1564        throw ImageException::createFromPhpError();
1565    }
1566    return $result;
1567}
1568
1569
1570/**
1571 * imagejpeg creates a JPEG file from
1572 * the given image.
1573 *
1574 * @param resource $image An image resource, returned by one of the image creation functions,
1575 * such as imagecreatetruecolor.
1576 * @param mixed $to The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly.
1577 * @param int $quality quality is optional, and ranges from 0 (worst
1578 * quality, smaller file) to 100 (best quality, biggest file). The
1579 * default (-1) uses the default IJG quality value (about 75).
1580 * @throws ImageException
1581 *
1582 */
1583function imagejpeg($image, $to = null, int $quality = -1): void
1584{
1585    error_clear_last();
1586    $result = \imagejpeg($image, $to, $quality);
1587    if ($result === false) {
1588        throw ImageException::createFromPhpError();
1589    }
1590}
1591
1592
1593/**
1594 * Set the alpha blending flag to use layering effects.
1595 *
1596 * @param resource $image An image resource, returned by one of the image creation functions,
1597 * such as imagecreatetruecolor.
1598 * @param int $effect One of the following constants:
1599 *
1600 *
1601 * IMG_EFFECT_REPLACE
1602 *
1603 *
1604 * Use pixel replacement (equivalent of passing TRUE to
1605 * imagealphablending)
1606 *
1607 *
1608 *
1609 *
1610 * IMG_EFFECT_ALPHABLEND
1611 *
1612 *
1613 * Use normal pixel blending (equivalent of passing FALSE to
1614 * imagealphablending)
1615 *
1616 *
1617 *
1618 *
1619 * IMG_EFFECT_NORMAL
1620 *
1621 *
1622 * Same as IMG_EFFECT_ALPHABLEND.
1623 *
1624 *
1625 *
1626 *
1627 * IMG_EFFECT_OVERLAY
1628 *
1629 *
1630 * Overlay has the effect that black background pixels will remain
1631 * black, white background pixels will remain white, but grey
1632 * background pixels will take the colour of the foreground pixel.
1633 *
1634 *
1635 *
1636 *
1637 * IMG_EFFECT_MULTIPLY
1638 *
1639 *
1640 * Overlays with a multiply effect.
1641 *
1642 *
1643 *
1644 *
1645 * @throws ImageException
1646 *
1647 */
1648function imagelayereffect($image, int $effect): void
1649{
1650    error_clear_last();
1651    $result = \imagelayereffect($image, $effect);
1652    if ($result === false) {
1653        throw ImageException::createFromPhpError();
1654    }
1655}
1656
1657
1658/**
1659 * Draws a line between the two given points.
1660 *
1661 * @param resource $image An image resource, returned by one of the image creation functions,
1662 * such as imagecreatetruecolor.
1663 * @param int $x1 x-coordinate for first point.
1664 * @param int $y1 y-coordinate for first point.
1665 * @param int $x2 x-coordinate for second point.
1666 * @param int $y2 y-coordinate for second point.
1667 * @param int $color The line color. A color identifier created with imagecolorallocate.
1668 * @throws ImageException
1669 *
1670 */
1671function imageline($image, int $x1, int $y1, int $x2, int $y2, int $color): void
1672{
1673    error_clear_last();
1674    $result = \imageline($image, $x1, $y1, $x2, $y2, $color);
1675    if ($result === false) {
1676        throw ImageException::createFromPhpError();
1677    }
1678}
1679
1680
1681/**
1682 * imageloadfont loads a user-defined bitmap and returns
1683 * its identifier.
1684 *
1685 * @param string $file The font file format is currently binary and architecture
1686 * dependent.  This means you should generate the font files on the
1687 * same type of CPU as the machine you are running PHP on.
1688 *
1689 *
1690 * Font file format
1691 *
1692 *
1693 *
1694 * byte position
1695 * C data type
1696 * description
1697 *
1698 *
1699 *
1700 *
1701 * byte 0-3
1702 * int
1703 * number of characters in the font
1704 *
1705 *
1706 * byte 4-7
1707 * int
1708 *
1709 * value of first character in the font (often 32 for space)
1710 *
1711 *
1712 *
1713 * byte 8-11
1714 * int
1715 * pixel width of each character
1716 *
1717 *
1718 * byte 12-15
1719 * int
1720 * pixel height of each character
1721 *
1722 *
1723 * byte 16-
1724 * char
1725 *
1726 * array with character data, one byte per pixel in each
1727 * character, for a total of (nchars*width*height) bytes.
1728 *
1729 *
1730 *
1731 *
1732 *
1733 * @return int The font identifier which is always bigger than 5 to avoid conflicts with
1734 * built-in fontss.
1735 * @throws ImageException
1736 *
1737 */
1738function imageloadfont(string $file): int
1739{
1740    error_clear_last();
1741    $result = \imageloadfont($file);
1742    if ($result === false) {
1743        throw ImageException::createFromPhpError();
1744    }
1745    return $result;
1746}
1747
1748
1749/**
1750 * imageopenpolygon draws an open polygon on the given
1751 * image. Contrary to imagepolygon,
1752 * no line is drawn between the last and the first point.
1753 *
1754 * @param resource $image An image resource, returned by one of the image creation functions,
1755 * such as imagecreatetruecolor.
1756 * @param array $points An array containing the polygon's vertices, e.g.:
1757 *
1758 *
1759 *
1760 *
1761 * points[0]
1762 * = x0
1763 *
1764 *
1765 * points[1]
1766 * = y0
1767 *
1768 *
1769 * points[2]
1770 * = x1
1771 *
1772 *
1773 * points[3]
1774 * = y1
1775 *
1776 *
1777 *
1778 *
1779 * @param int $num_points Total number of points (vertices), which must be at least 3.
1780 * @param int $color A color identifier created with imagecolorallocate.
1781 * @throws ImageException
1782 *
1783 */
1784function imageopenpolygon($image, array $points, int $num_points, int $color): void
1785{
1786    error_clear_last();
1787    $result = \imageopenpolygon($image, $points, $num_points, $color);
1788    if ($result === false) {
1789        throw ImageException::createFromPhpError();
1790    }
1791}
1792
1793
1794/**
1795 * Outputs or saves a PNG image from the given
1796 * image.
1797 *
1798 * @param resource $image An image resource, returned by one of the image creation functions,
1799 * such as imagecreatetruecolor.
1800 * @param mixed $to The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly.
1801 *
1802 * NULL is invalid if the quality and
1803 * filters arguments are not used.
1804 * @param int $quality Compression level: from 0 (no compression) to 9.
1805 * The default (-1) uses the zlib compression default.
1806 * For more information see the zlib manual.
1807 * @param int $filters Allows reducing the PNG file size. It is a bitmask field which may be
1808 * set to any combination of the PNG_FILTER_XXX
1809 * constants. PNG_NO_FILTER or
1810 * PNG_ALL_FILTERS may also be used to respectively
1811 * disable or activate all filters.
1812 * The default value (-1) disables filtering.
1813 * @throws ImageException
1814 *
1815 */
1816function imagepng($image, $to = null, int $quality = -1, int $filters = -1): void
1817{
1818    error_clear_last();
1819    $result = \imagepng($image, $to, $quality, $filters);
1820    if ($result === false) {
1821        throw ImageException::createFromPhpError();
1822    }
1823}
1824
1825
1826/**
1827 * imagepolygon creates a polygon in the given
1828 * image.
1829 *
1830 * @param resource $image An image resource, returned by one of the image creation functions,
1831 * such as imagecreatetruecolor.
1832 * @param array $points An array containing the polygon's vertices, e.g.:
1833 *
1834 *
1835 *
1836 *
1837 * points[0]
1838 * = x0
1839 *
1840 *
1841 * points[1]
1842 * = y0
1843 *
1844 *
1845 * points[2]
1846 * = x1
1847 *
1848 *
1849 * points[3]
1850 * = y1
1851 *
1852 *
1853 *
1854 *
1855 * @param int $num_points Total number of points (vertices), which must be at least 3.
1856 * @param int $color A color identifier created with imagecolorallocate.
1857 * @throws ImageException
1858 *
1859 */
1860function imagepolygon($image, array $points, int $num_points, int $color): void
1861{
1862    error_clear_last();
1863    $result = \imagepolygon($image, $points, $num_points, $color);
1864    if ($result === false) {
1865        throw ImageException::createFromPhpError();
1866    }
1867}
1868
1869
1870/**
1871 * imagerectangle creates a rectangle starting at
1872 * the specified coordinates.
1873 *
1874 * @param resource $image An image resource, returned by one of the image creation functions,
1875 * such as imagecreatetruecolor.
1876 * @param int $x1 Upper left x coordinate.
1877 * @param int $y1 Upper left y coordinate
1878 * 0, 0 is the top left corner of the image.
1879 * @param int $x2 Bottom right x coordinate.
1880 * @param int $y2 Bottom right y coordinate.
1881 * @param int $color A color identifier created with imagecolorallocate.
1882 * @throws ImageException
1883 *
1884 */
1885function imagerectangle($image, int $x1, int $y1, int $x2, int $y2, int $color): void
1886{
1887    error_clear_last();
1888    $result = \imagerectangle($image, $x1, $y1, $x2, $y2, $color);
1889    if ($result === false) {
1890        throw ImageException::createFromPhpError();
1891    }
1892}
1893
1894
1895/**
1896 * Rotates the image image using the given
1897 * angle in degrees.
1898 *
1899 * The center of rotation is the center of the image, and the rotated
1900 * image may have different dimensions than the original image.
1901 *
1902 * @param resource $image An image resource, returned by one of the image creation functions,
1903 * such as imagecreatetruecolor.
1904 * @param float $angle Rotation angle, in degrees. The rotation angle is interpreted as the
1905 * number of degrees to rotate the image anticlockwise.
1906 * @param int $bgd_color Specifies the color of the uncovered zone after the rotation
1907 * @param int $dummy This parameter is unused.
1908 * @return resource Returns an image resource for the rotated image.
1909 * @throws ImageException
1910 *
1911 */
1912function imagerotate($image, float $angle, int $bgd_color, int $dummy = 0)
1913{
1914    error_clear_last();
1915    $result = \imagerotate($image, $angle, $bgd_color, $dummy);
1916    if ($result === false) {
1917        throw ImageException::createFromPhpError();
1918    }
1919    return $result;
1920}
1921
1922
1923/**
1924 * imagesavealpha sets the flag which determines whether to retain
1925 * full alpha channel information (as opposed to single-color transparency)
1926 * when saving PNG images.
1927 *
1928 * Alphablending has to be disabled (imagealphablending($im, false))
1929 * to retain the alpha-channel in the first place.
1930 *
1931 * @param resource $image An image resource, returned by one of the image creation functions,
1932 * such as imagecreatetruecolor.
1933 * @param bool $saveflag Whether to save the alpha channel or not. Defaults to FALSE.
1934 * @throws ImageException
1935 *
1936 */
1937function imagesavealpha($image, bool $saveflag): void
1938{
1939    error_clear_last();
1940    $result = \imagesavealpha($image, $saveflag);
1941    if ($result === false) {
1942        throw ImageException::createFromPhpError();
1943    }
1944}
1945
1946
1947/**
1948 * imagescale scales an image using the given
1949 * interpolation algorithm.
1950 *
1951 * @param resource $image An image resource, returned by one of the image creation functions,
1952 * such as imagecreatetruecolor.
1953 * @param int $new_width The width to scale the image to.
1954 * @param int $new_height The height to scale the image to. If omitted or negative, the aspect
1955 * ratio will be preserved.
1956 * @param int $mode One of IMG_NEAREST_NEIGHBOUR,
1957 * IMG_BILINEAR_FIXED,
1958 * IMG_BICUBIC,
1959 * IMG_BICUBIC_FIXED or anything else (will use two
1960 * pass).
1961 *
1962 *
1963 * IMG_WEIGHTED4 is not yet supported.
1964 *
1965 *
1966 * @return resource Return the scaled image resource on success.
1967 * @throws ImageException
1968 *
1969 */
1970function imagescale($image, int $new_width, int $new_height = -1, int $mode = IMG_BILINEAR_FIXED)
1971{
1972    error_clear_last();
1973    $result = \imagescale($image, $new_width, $new_height, $mode);
1974    if ($result === false) {
1975        throw ImageException::createFromPhpError();
1976    }
1977    return $result;
1978}
1979
1980
1981/**
1982 * imagesetbrush sets the brush image to be
1983 * used by all line drawing functions (such as imageline
1984 * and imagepolygon) when drawing with the special
1985 * colors IMG_COLOR_BRUSHED or
1986 * IMG_COLOR_STYLEDBRUSHED.
1987 *
1988 * @param resource $image An image resource, returned by one of the image creation functions,
1989 * such as imagecreatetruecolor.
1990 * @param resource $brush An image resource.
1991 * @throws ImageException
1992 *
1993 */
1994function imagesetbrush($image, $brush): void
1995{
1996    error_clear_last();
1997    $result = \imagesetbrush($image, $brush);
1998    if ($result === false) {
1999        throw ImageException::createFromPhpError();
2000    }
2001}
2002
2003
2004/**
2005 * imagesetclip sets the current clipping rectangle, i.e.
2006 * the area beyond which no pixels will be drawn.
2007 *
2008 * @param resource $im An image resource, returned by one of the image creation functions,
2009 * such as imagecreatetruecolor.
2010 * @param int $x1 The x-coordinate of the upper left corner.
2011 * @param int $y1 The y-coordinate of the upper left corner.
2012 * @param int $x2 The x-coordinate of the lower right corner.
2013 * @param int $y2 The y-coordinate of the lower right corner.
2014 * @throws ImageException
2015 *
2016 */
2017function imagesetclip($im, int $x1, int $y1, int $x2, int $y2): void
2018{
2019    error_clear_last();
2020    $result = \imagesetclip($im, $x1, $y1, $x2, $y2);
2021    if ($result === false) {
2022        throw ImageException::createFromPhpError();
2023    }
2024}
2025
2026
2027/**
2028 * Sets the interpolation method, setting an interpolation method affects the rendering
2029 * of various functions in GD, such as the imagerotate function.
2030 *
2031 * @param resource $image An image resource, returned by one of the image creation functions,
2032 * such as imagecreatetruecolor.
2033 * @param int $method The interpolation method, which can be one of the following:
2034 *
2035 *
2036 *
2037 * IMG_BELL: Bell filter.
2038 *
2039 *
2040 *
2041 *
2042 * IMG_BESSEL: Bessel filter.
2043 *
2044 *
2045 *
2046 *
2047 * IMG_BICUBIC: Bicubic interpolation.
2048 *
2049 *
2050 *
2051 *
2052 * IMG_BICUBIC_FIXED: Fixed point implementation of the bicubic interpolation.
2053 *
2054 *
2055 *
2056 *
2057 * IMG_BILINEAR_FIXED: Fixed point implementation of the  bilinear interpolation (default (also on image creation)).
2058 *
2059 *
2060 *
2061 *
2062 * IMG_BLACKMAN: Blackman window function.
2063 *
2064 *
2065 *
2066 *
2067 * IMG_BOX: Box blur filter.
2068 *
2069 *
2070 *
2071 *
2072 * IMG_BSPLINE: Spline interpolation.
2073 *
2074 *
2075 *
2076 *
2077 * IMG_CATMULLROM: Cubic Hermite spline interpolation.
2078 *
2079 *
2080 *
2081 *
2082 * IMG_GAUSSIAN: Gaussian function.
2083 *
2084 *
2085 *
2086 *
2087 * IMG_GENERALIZED_CUBIC: Generalized cubic spline fractal interpolation.
2088 *
2089 *
2090 *
2091 *
2092 * IMG_HERMITE: Hermite interpolation.
2093 *
2094 *
2095 *
2096 *
2097 * IMG_HAMMING: Hamming filter.
2098 *
2099 *
2100 *
2101 *
2102 * IMG_HANNING: Hanning filter.
2103 *
2104 *
2105 *
2106 *
2107 * IMG_MITCHELL: Mitchell filter.
2108 *
2109 *
2110 *
2111 *
2112 * IMG_POWER: Power interpolation.
2113 *
2114 *
2115 *
2116 *
2117 * IMG_QUADRATIC: Inverse quadratic interpolation.
2118 *
2119 *
2120 *
2121 *
2122 * IMG_SINC: Sinc function.
2123 *
2124 *
2125 *
2126 *
2127 * IMG_NEAREST_NEIGHBOUR: Nearest neighbour interpolation.
2128 *
2129 *
2130 *
2131 *
2132 * IMG_WEIGHTED4: Weighting filter.
2133 *
2134 *
2135 *
2136 *
2137 * IMG_TRIANGLE: Triangle interpolation.
2138 *
2139 *
2140 *
2141 * @throws ImageException
2142 *
2143 */
2144function imagesetinterpolation($image, int $method = IMG_BILINEAR_FIXED): void
2145{
2146    error_clear_last();
2147    $result = \imagesetinterpolation($image, $method);
2148    if ($result === false) {
2149        throw ImageException::createFromPhpError();
2150    }
2151}
2152
2153
2154/**
2155 * imagesetpixel draws a pixel at the specified
2156 * coordinate.
2157 *
2158 * @param resource $image An image resource, returned by one of the image creation functions,
2159 * such as imagecreatetruecolor.
2160 * @param int $x x-coordinate.
2161 * @param int $y y-coordinate.
2162 * @param int $color A color identifier created with imagecolorallocate.
2163 * @throws ImageException
2164 *
2165 */
2166function imagesetpixel($image, int $x, int $y, int $color): void
2167{
2168    error_clear_last();
2169    $result = \imagesetpixel($image, $x, $y, $color);
2170    if ($result === false) {
2171        throw ImageException::createFromPhpError();
2172    }
2173}
2174
2175
2176/**
2177 * imagesetstyle sets the style to be used by all
2178 * line drawing functions (such as imageline
2179 * and imagepolygon) when drawing with the special
2180 * color IMG_COLOR_STYLED or lines of images with color
2181 * IMG_COLOR_STYLEDBRUSHED.
2182 *
2183 * @param resource $image An image resource, returned by one of the image creation functions,
2184 * such as imagecreatetruecolor.
2185 * @param array $style An array of pixel colors. You can use the
2186 * IMG_COLOR_TRANSPARENT constant to add a
2187 * transparent pixel.
2188 * Note that style must not be an empty array.
2189 * @throws ImageException
2190 *
2191 */
2192function imagesetstyle($image, array $style): void
2193{
2194    error_clear_last();
2195    $result = \imagesetstyle($image, $style);
2196    if ($result === false) {
2197        throw ImageException::createFromPhpError();
2198    }
2199}
2200
2201
2202/**
2203 * imagesetthickness sets the thickness of the lines
2204 * drawn when drawing rectangles, polygons, arcs etc. to
2205 * thickness pixels.
2206 *
2207 * @param resource $image An image resource, returned by one of the image creation functions,
2208 * such as imagecreatetruecolor.
2209 * @param int $thickness Thickness, in pixels.
2210 * @throws ImageException
2211 *
2212 */
2213function imagesetthickness($image, int $thickness): void
2214{
2215    error_clear_last();
2216    $result = \imagesetthickness($image, $thickness);
2217    if ($result === false) {
2218        throw ImageException::createFromPhpError();
2219    }
2220}
2221
2222
2223/**
2224 * imagesettile sets the tile image to be
2225 * used by all region filling functions (such as imagefill
2226 * and imagefilledpolygon) when filling with the special
2227 * color IMG_COLOR_TILED.
2228 *
2229 * A tile is an image used to fill an area with a repeated pattern. Any
2230 * GD image can be used as a tile, and by setting the transparent color index of the tile
2231 * image with imagecolortransparent, a tile allows certain parts
2232 * of the underlying area to shine through can be created.
2233 *
2234 * @param resource $image An image resource, returned by one of the image creation functions,
2235 * such as imagecreatetruecolor.
2236 * @param resource $tile The image resource to be used as a tile.
2237 * @throws ImageException
2238 *
2239 */
2240function imagesettile($image, $tile): void
2241{
2242    error_clear_last();
2243    $result = \imagesettile($image, $tile);
2244    if ($result === false) {
2245        throw ImageException::createFromPhpError();
2246    }
2247}
2248
2249
2250/**
2251 * Draws a string at the given coordinates.
2252 *
2253 * @param resource $image An image resource, returned by one of the image creation functions,
2254 * such as imagecreatetruecolor.
2255 * @param int $font Can be 1, 2, 3, 4, 5 for built-in
2256 * fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your
2257 * own font identifiers registered with imageloadfont.
2258 * @param int $x x-coordinate of the upper left corner.
2259 * @param int $y y-coordinate of the upper left corner.
2260 * @param string $string The string to be written.
2261 * @param int $color A color identifier created with imagecolorallocate.
2262 * @throws ImageException
2263 *
2264 */
2265function imagestring($image, int $font, int $x, int $y, string $string, int $color): void
2266{
2267    error_clear_last();
2268    $result = \imagestring($image, $font, $x, $y, $string, $color);
2269    if ($result === false) {
2270        throw ImageException::createFromPhpError();
2271    }
2272}
2273
2274
2275/**
2276 * Draws a string vertically at the given
2277 * coordinates.
2278 *
2279 * @param resource $image An image resource, returned by one of the image creation functions,
2280 * such as imagecreatetruecolor.
2281 * @param int $font Can be 1, 2, 3, 4, 5 for built-in
2282 * fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your
2283 * own font identifiers registered with imageloadfont.
2284 * @param int $x x-coordinate of the bottom left corner.
2285 * @param int $y y-coordinate of the bottom left corner.
2286 * @param string $string The string to be written.
2287 * @param int $color A color identifier created with imagecolorallocate.
2288 * @throws ImageException
2289 *
2290 */
2291function imagestringup($image, int $font, int $x, int $y, string $string, int $color): void
2292{
2293    error_clear_last();
2294    $result = \imagestringup($image, $font, $x, $y, $string, $color);
2295    if ($result === false) {
2296        throw ImageException::createFromPhpError();
2297    }
2298}
2299
2300
2301/**
2302 * Returns the width of the given image resource.
2303 *
2304 * @param resource $image An image resource, returned by one of the image creation functions,
2305 * such as imagecreatetruecolor.
2306 * @return int Return the width of the images.
2307 * @throws ImageException
2308 *
2309 */
2310function imagesx($image): int
2311{
2312    error_clear_last();
2313    $result = \imagesx($image);
2314    if ($result === false) {
2315        throw ImageException::createFromPhpError();
2316    }
2317    return $result;
2318}
2319
2320
2321/**
2322 * Returns the height of the given image resource.
2323 *
2324 * @param resource $image An image resource, returned by one of the image creation functions,
2325 * such as imagecreatetruecolor.
2326 * @return int Return the height of the images.
2327 * @throws ImageException
2328 *
2329 */
2330function imagesy($image): int
2331{
2332    error_clear_last();
2333    $result = \imagesy($image);
2334    if ($result === false) {
2335        throw ImageException::createFromPhpError();
2336    }
2337    return $result;
2338}
2339
2340
2341/**
2342 * imagetruecolortopalette converts a truecolor image
2343 * to a palette image. The code for this function was originally drawn from
2344 * the Independent JPEG Group library code, which is excellent. The code
2345 * has been modified to preserve as much alpha channel information as
2346 * possible in the resulting palette, in addition to preserving colors as
2347 * well as possible. This does not work as well as might be hoped. It is
2348 * usually best to simply produce a truecolor output image instead, which
2349 * guarantees the highest output quality.
2350 *
2351 * @param resource $image An image resource, returned by one of the image creation functions,
2352 * such as imagecreatetruecolor.
2353 * @param bool $dither Indicates if the image should be dithered - if it is TRUE then
2354 * dithering will be used which will result in a more speckled image but
2355 * with better color approximation.
2356 * @param int $ncolors Sets the maximum number of colors that should be retained in the palette.
2357 * @throws ImageException
2358 *
2359 */
2360function imagetruecolortopalette($image, bool $dither, int $ncolors): void
2361{
2362    error_clear_last();
2363    $result = \imagetruecolortopalette($image, $dither, $ncolors);
2364    if ($result === false) {
2365        throw ImageException::createFromPhpError();
2366    }
2367}
2368
2369
2370/**
2371 * This function calculates and returns the bounding box in pixels
2372 * for a TrueType text.
2373 *
2374 * @param float $size The font size in points.
2375 * @param float $angle Angle in degrees in which text will be measured.
2376 * @param string $fontfile The path to the TrueType font you wish to use.
2377 *
2378 * Depending on which version of the GD library PHP is using, when
2379 * fontfile does not begin with a leading
2380 * / then .ttf will be appended
2381 * to the filename and the library will attempt to search for that
2382 * filename along a library-defined font path.
2383 *
2384 * When using versions of the GD library lower than 2.0.18, a space character,
2385 * rather than a semicolon, was used as the 'path separator' for different font files.
2386 * Unintentional use of this feature will result in the warning message:
2387 * Warning: Could not find/open font. For these affected versions, the
2388 * only solution is moving the font to a path which does not contain spaces.
2389 *
2390 * In many cases where a font resides in the same directory as the script using it
2391 * the following trick will alleviate any include problems.
2392 *
2393 *
2394 * ]]>
2395 *
2396 *
2397 * Note that open_basedir does
2398 * not apply to fontfile.
2399 * @param string $text The string to be measured.
2400 * @return array imagettfbbox returns an array with 8
2401 * elements representing four points making the bounding box of the
2402 * text on success and FALSE on error.
2403 *
2404 *
2405 *
2406 *
2407 * key
2408 * contents
2409 *
2410 *
2411 *
2412 *
2413 * 0
2414 * lower left corner, X position
2415 *
2416 *
2417 * 1
2418 * lower left corner, Y position
2419 *
2420 *
2421 * 2
2422 * lower right corner, X position
2423 *
2424 *
2425 * 3
2426 * lower right corner, Y position
2427 *
2428 *
2429 * 4
2430 * upper right corner, X position
2431 *
2432 *
2433 * 5
2434 * upper right corner, Y position
2435 *
2436 *
2437 * 6
2438 * upper left corner, X position
2439 *
2440 *
2441 * 7
2442 * upper left corner, Y position
2443 *
2444 *
2445 *
2446 *
2447 *
2448 * The points are relative to the text regardless of the
2449 * angle, so "upper left" means in the top left-hand
2450 * corner seeing the text horizontally.
2451 * @throws ImageException
2452 *
2453 */
2454function imagettfbbox(float $size, float $angle, string $fontfile, string $text): array
2455{
2456    error_clear_last();
2457    $result = \imagettfbbox($size, $angle, $fontfile, $text);
2458    if ($result === false) {
2459        throw ImageException::createFromPhpError();
2460    }
2461    return $result;
2462}
2463
2464
2465/**
2466 * Writes the given text into the image using TrueType
2467 * fonts.
2468 *
2469 * @param resource $image An image resource, returned by one of the image creation functions,
2470 * such as imagecreatetruecolor.
2471 * @param float $size The font size in points.
2472 * @param float $angle The angle in degrees, with 0 degrees being left-to-right reading text.
2473 * Higher values represent a counter-clockwise rotation. For example, a
2474 * value of 90 would result in bottom-to-top reading text.
2475 * @param int $x The coordinates given by x and
2476 * y will define the basepoint of the first
2477 * character (roughly the lower-left corner of the character). This
2478 * is different from the imagestring, where
2479 * x and y define the
2480 * upper-left corner of the first character. For example, "top left"
2481 * is 0, 0.
2482 * @param int $y The y-ordinate. This sets the position of the fonts baseline, not the
2483 * very bottom of the character.
2484 * @param int $color The color index. Using the negative of a color index has the effect of
2485 * turning off antialiasing. See imagecolorallocate.
2486 * @param string $fontfile The path to the TrueType font you wish to use.
2487 *
2488 * Depending on which version of the GD library PHP is using, when
2489 * fontfile does not begin with a leading
2490 * / then .ttf will be appended
2491 * to the filename and the library will attempt to search for that
2492 * filename along a library-defined font path.
2493 *
2494 * When using versions of the GD library lower than 2.0.18, a space character,
2495 * rather than a semicolon, was used as the 'path separator' for different font files.
2496 * Unintentional use of this feature will result in the warning message:
2497 * Warning: Could not find/open font. For these affected versions, the
2498 * only solution is moving the font to a path which does not contain spaces.
2499 *
2500 * In many cases where a font resides in the same directory as the script using it
2501 * the following trick will alleviate any include problems.
2502 *
2503 *
2504 * ]]>
2505 *
2506 *
2507 * Note that open_basedir does
2508 * not apply to fontfile.
2509 * @param string $text The text string in UTF-8 encoding.
2510 *
2511 * May include decimal numeric character references (of the form:
2512 * &amp;#8364;) to access characters in a font beyond position 127.
2513 * The hexadecimal format (like &amp;#xA9;) is supported.
2514 * Strings in UTF-8 encoding can be passed directly.
2515 *
2516 * Named entities, such as &amp;copy;, are not supported. Consider using
2517 * html_entity_decode
2518 * to decode these named entities into UTF-8 strings.
2519 *
2520 * If a character is used in the string which is not supported by the
2521 * font, a hollow rectangle will replace the character.
2522 * @return array Returns an array with 8 elements representing four points making the
2523 * bounding box of the text. The order of the points is lower left, lower
2524 * right, upper right, upper left. The points are relative to the text
2525 * regardless of the angle, so "upper left" means in the top left-hand
2526 * corner when you see the text horizontally.
2527 * @throws ImageException
2528 *
2529 */
2530function imagettftext($image, float $size, float $angle, int $x, int $y, int $color, string $fontfile, string $text): array
2531{
2532    error_clear_last();
2533    $result = \imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $text);
2534    if ($result === false) {
2535        throw ImageException::createFromPhpError();
2536    }
2537    return $result;
2538}
2539
2540
2541/**
2542 * imagewbmp outputs or save a WBMP
2543 * version of the given image.
2544 *
2545 * @param resource $image An image resource, returned by one of the image creation functions,
2546 * such as imagecreatetruecolor.
2547 * @param mixed $to The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly.
2548 * @param int $foreground You can set the foreground color with this parameter by setting an
2549 * identifier obtained from imagecolorallocate.
2550 * The default foreground color is black.
2551 * @throws ImageException
2552 *
2553 */
2554function imagewbmp($image, $to = null, int $foreground = null): void
2555{
2556    error_clear_last();
2557    if ($foreground !== null) {
2558        $result = \imagewbmp($image, $to, $foreground);
2559    } else {
2560        $result = \imagewbmp($image, $to);
2561    }
2562    if ($result === false) {
2563        throw ImageException::createFromPhpError();
2564    }
2565}
2566
2567
2568/**
2569 * Outputs or saves a WebP version of the given image.
2570 *
2571 * @param resource $image An image resource, returned by one of the image creation functions,
2572 * such as imagecreatetruecolor.
2573 * @param mixed $to The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly.
2574 * @param int $quality quality ranges from 0 (worst
2575 * quality, smaller file) to 100 (best quality, biggest file).
2576 * @throws ImageException
2577 *
2578 */
2579function imagewebp($image, $to = null, int $quality = 80): void
2580{
2581    error_clear_last();
2582    $result = \imagewebp($image, $to, $quality);
2583    if ($result === false) {
2584        throw ImageException::createFromPhpError();
2585    }
2586}
2587
2588
2589/**
2590 * Outputs or save an XBM version of the given
2591 * image.
2592 *
2593 * @param resource $image An image resource, returned by one of the image creation functions,
2594 * such as imagecreatetruecolor.
2595 * @param string|null $filename The path to save the file to, given as string. If NULL, the raw image stream will be output directly.
2596 *
2597 * The filename (without the .xbm extension) is also
2598 * used for the C identifiers of the XBM, whereby non
2599 * alphanumeric characters of the current locale are substituted by
2600 * underscores. If filename is set to NULL,
2601 * image is used to build the C identifiers.
2602 * @param int $foreground You can set the foreground color with this parameter by setting an
2603 * identifier obtained from imagecolorallocate.
2604 * The default foreground color is black. All other colors are treated as
2605 * background.
2606 * @throws ImageException
2607 *
2608 */
2609function imagexbm($image, ?string $filename, int $foreground = null): void
2610{
2611    error_clear_last();
2612    if ($foreground !== null) {
2613        $result = \imagexbm($image, $filename, $foreground);
2614    } else {
2615        $result = \imagexbm($image, $filename);
2616    }
2617    if ($result === false) {
2618        throw ImageException::createFromPhpError();
2619    }
2620}
2621
2622
2623/**
2624 * Embeds binary IPTC data into a JPEG image.
2625 *
2626 * @param string $iptcdata The data to be written.
2627 * @param string $jpeg_file_name Path to the JPEG image.
2628 * @param int $spool Spool flag. If the spool flag is less than 2 then the JPEG will be
2629 * returned as a string. Otherwise the JPEG will be printed to STDOUT.
2630 * @return string|bool If spool is less than 2, the JPEG will be returned. Otherwise returns TRUE on success.
2631 * @throws ImageException
2632 *
2633 */
2634function iptcembed(string $iptcdata, string $jpeg_file_name, int $spool = 0)
2635{
2636    error_clear_last();
2637    $result = \iptcembed($iptcdata, $jpeg_file_name, $spool);
2638    if ($result === false) {
2639        throw ImageException::createFromPhpError();
2640    }
2641    return $result;
2642}
2643
2644
2645/**
2646 * Parses an IPTC block into its single tags.
2647 *
2648 * @param string $iptcblock A binary IPTC block.
2649 * @return array Returns an array using the tagmarker as an index and the value as the
2650 * value. It returns FALSE on error or if no IPTC data was found.
2651 * @throws ImageException
2652 *
2653 */
2654function iptcparse(string $iptcblock): array
2655{
2656    error_clear_last();
2657    $result = \iptcparse($iptcblock);
2658    if ($result === false) {
2659        throw ImageException::createFromPhpError();
2660    }
2661    return $result;
2662}
2663
2664
2665/**
2666 * Converts a JPEG file into a WBMP file.
2667 *
2668 * @param string $jpegname Path to JPEG file.
2669 * @param string $wbmpname Path to destination WBMP file.
2670 * @param int $dest_height Destination image height.
2671 * @param int $dest_width Destination image width.
2672 * @param int $threshold Threshold value, between 0 and 8 (inclusive).
2673 * @throws ImageException
2674 *
2675 */
2676function jpeg2wbmp(string $jpegname, string $wbmpname, int $dest_height, int $dest_width, int $threshold): void
2677{
2678    error_clear_last();
2679    $result = \jpeg2wbmp($jpegname, $wbmpname, $dest_height, $dest_width, $threshold);
2680    if ($result === false) {
2681        throw ImageException::createFromPhpError();
2682    }
2683}
2684
2685
2686/**
2687 * Converts a PNG file into a WBMP file.
2688 *
2689 * @param string $pngname Path to PNG file.
2690 * @param string $wbmpname Path to destination WBMP file.
2691 * @param int $dest_height Destination image height.
2692 * @param int $dest_width Destination image width.
2693 * @param int $threshold Threshold value, between 0 and 8 (inclusive).
2694 * @throws ImageException
2695 *
2696 */
2697function png2wbmp(string $pngname, string $wbmpname, int $dest_height, int $dest_width, int $threshold): void
2698{
2699    error_clear_last();
2700    $result = \png2wbmp($pngname, $wbmpname, $dest_height, $dest_width, $threshold);
2701    if ($result === false) {
2702        throw ImageException::createFromPhpError();
2703    }
2704}
2705