xref: /PHP-8.1/ext/gd/tests/jpeg2png.phpt (revision a375d547)
1--TEST--
2jpeg <--> png conversion test
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7    if (!function_exists("imagecreatefrompng") || !function_exists("imagepng")) {
8        die("skip png support unavailable");
9    }
10    if (!function_exists("imagecreatefromjpeg") || !function_exists("imagejpeg")) {
11        die("skip jpeg support unavailable");
12    }
13?>
14--FILE--
15<?php
16    $cwd = __DIR__;
17
18    echo "PNG to JPEG conversion: ";
19    echo imagejpeg(imagecreatefrompng($cwd . "/conv_test.png"), $cwd . "/test_jpeg.jpeg") ? 'ok' : 'failed';
20    echo "\n";
21
22    echo "Generated JPEG to PNG conversion: ";
23    echo imagepng(imagecreatefromjpeg($cwd . "/test_jpeg.jpeg"), $cwd . "/test_jpng.png") ? 'ok' : 'failed';
24    echo "\n";
25
26    echo "JPEG to PNG conversion: ";
27    echo imagepng(imagecreatefromjpeg($cwd . "/conv_test.jpg"), $cwd . "/test_png.png") ? 'ok' : 'failed';
28    echo "\n";
29
30    echo "Generated PNG to JPEG conversion: ";
31    echo imagejpeg(imagecreatefrompng($cwd . "/test_png.png"), $cwd . "/test_pjpeg.jpeg") ? 'ok' : 'failed';
32    echo "\n";
33
34    @unlink($cwd . "/test_jpeg.jpeg");
35    @unlink($cwd . "/test_jpng.png");
36    @unlink($cwd . "/test_png.png");
37    @unlink($cwd . "/test_pjpeg.jpeg");
38?>
39--EXPECT--
40PNG to JPEG conversion: ok
41Generated JPEG to PNG conversion: ok
42JPEG to PNG conversion: ok
43Generated PNG to JPEG conversion: ok
44