Skip to content

Overhaul GD test helpers and affected tests #17309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions ext/gd/tests/func.inc
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,8 @@ function test_image_equals_image(GdImage $expected, GdImage $actual, bool $save_

/**
* Returns the truecolor version of an image.
*
* @param resource $image
* @return resource
*/
function test_to_truecolor($image)
function test_to_truecolor(GdImage $image): GdImage
{
if (imageistruecolor($image)) {
return $image;
Expand All @@ -150,11 +147,8 @@ function test_to_truecolor($image)
*
* The image is saved right beside the temporary .php test file with the
* extension .out.png.
*
* @param resource $image
* @return void
*/
function save_actual_image($image)
function save_actual_image(GdImage $image): void
{
$pathinfo = pathinfo($_SERVER['SCRIPT_FILENAME']);
$filename = "{$pathinfo['dirname']}/{$pathinfo['filename']}.out.png";
Expand Down
25 changes: 5 additions & 20 deletions ext/gd/tests/similarity.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@

/**
* Gets the individual components of an RGB value.
*
* @param int $color
* @param int $red
* @param int $green
* @param int $blue
*
* @return void
*/
function get_rgb($color, &$red, &$green, &$blue)
function get_rgb(int $color, &$red, &$green, &$blue): void
{
// assumes $color is an RGB value
$red = ($color >> 16) & 0xFF;
Expand All @@ -25,13 +18,8 @@ function get_rgb($color, &$red, &$green, &$blue)

/**
* Calculates the euclidean distance of two RGB values.
*
* @param int $color1
* @param int $color2
*
* @return int
*/
function calc_pixel_distance($color1, $color2)
function calc_pixel_distance(int $color1, int $color2): float
{
get_rgb($color1, $red1, $green1, $blue1);
get_rgb($color2, $red2, $green2, $blue2);
Expand All @@ -43,13 +31,10 @@ function calc_pixel_distance($color1, $color2)
/**
* Calculates dissimilarity of two images.
*
* @param resource $image1
* @param resource $image2
*
* @return int The dissimilarity. 0 means the images are identical. The higher
* the value, the more dissimilar are the images.
* The dissimilarity. 0 means the images are identical. The higher
* the value, the more dissimilar are the images.
*/
function calc_image_dissimilarity($image1, $image2)
function calc_image_dissimilarity(GdImage $image1, GdImage $image2): float
{
// assumes image1 and image2 have same width and height
$dissimilarity = 0;
Expand Down