PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / lib / packages / Safe / generated / image.php

image.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at lib/packages/Safe/generated/image.php

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