Skip to content

Commit

Permalink
refactor: Suppress all GD warnings in PDQ Hash
Browse files Browse the repository at this point in the history
  • Loading branch information
octfx committed Jan 2, 2024
1 parent 4b7c09e commit 70d3c79
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/Services/ImageHash/Implementations/PDQHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,23 +577,23 @@ static function computeHashFromDCTOutput(
static function readImageFromFilename($filename, $downsample_first, $fromString)
{
if ($fromString) {
$orig_image = imagecreatefromstring($filename);
$orig_image = @imagecreatefromstring($filename);
} elseif (substr_compare($filename, '.jpg', -strlen('.jpg'), null, true) === 0) {
$orig_image = imagecreatefromjpeg($filename);
$orig_image = @imagecreatefromjpeg($filename);
if ($orig_image === false) {
$orig_image = @imagecreatefrompng($filename);
}
} elseif (substr_compare($filename, '.jpeg', -strlen('.jpeg'), null, true) === 0) {
$orig_image = imagecreatefromjpeg($filename);
$orig_image = @imagecreatefromjpeg($filename);
} elseif (substr_compare($filename, '.png', -strlen('.png'), null, true) === 0) {
$orig_image = @imagecreatefrompng($filename);
if ($orig_image === false) {
$orig_image = imagecreatefromjpeg($filename);
$orig_image = @imagecreatefromjpeg($filename);
}
} elseif (substr_compare($filename, '.gif', -strlen('.gif'), null, true) === 0) {
$orig_image = imagecreatefromgif($filename);
$orig_image = @imagecreatefromgif($filename);
} elseif (substr_compare($filename, '.webp', -strlen('.webp'), null, true) === 0) {
$orig_image = imagecreatefromwebp($filename);
$orig_image = @imagecreatefromwebp($filename);
} else {
throw new Exception('PDQHasher: could not handle filetype of ' . $filename);
}
Expand All @@ -606,7 +606,7 @@ static function readImageFromFilename($filename, $downsample_first, $fromString)
$orig_height = imagesy($orig_image);
$orig_width = imagesx($orig_image);
if ($orig_height > 128 || $orig_width > 128) {
$image = imagecreatetruecolor(128, 128);
$image = @imagecreatetruecolor(128, 128);
imagecopyresampled($image, $orig_image, 0, 0, 0, 0, 128, 128, $orig_width, $orig_height);
} else {
$image = $orig_image;
Expand Down

0 comments on commit 70d3c79

Please sign in to comment.