Skip to content

Commit

Permalink
ext/exif: Minor refactoring of exif_thumbnail() (#16111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgias authored Sep 29, 2024
1 parent fec2055 commit 291eef2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
19 changes: 10 additions & 9 deletions ext/exif/exif.c
Original file line number Diff line number Diff line change
Expand Up @@ -4699,7 +4699,6 @@ PHP_FUNCTION(exif_read_data)
PHP_FUNCTION(exif_thumbnail)
{
bool ret;
int arg_c = ZEND_NUM_ARGS();
image_info_type ImageInfo;
zval *stream;
zval *z_width = NULL, *z_height = NULL, *z_imagetype = NULL;
Expand Down Expand Up @@ -4731,7 +4730,7 @@ PHP_FUNCTION(exif_thumbnail)
RETURN_THROWS();
}

if (CHECK_NULL_PATH(Z_STRVAL_P(stream), Z_STRLEN_P(stream))) {
if (zend_str_has_nul_byte(Z_STR_P(stream))) {
zend_argument_value_error(1, "must not contain any null bytes");
RETURN_THROWS();
}
Expand All @@ -4756,17 +4755,19 @@ PHP_FUNCTION(exif_thumbnail)
exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_NOTICE, "Returning thumbnail(%d)", ImageInfo.Thumbnail.size);
#endif

ZVAL_STRINGL(return_value, ImageInfo.Thumbnail.data, ImageInfo.Thumbnail.size);
if (arg_c >= 3) {
if (!ImageInfo.Thumbnail.width || !ImageInfo.Thumbnail.height) {
if (!exif_scan_thumbnail(&ImageInfo)) {
ImageInfo.Thumbnail.width = ImageInfo.Thumbnail.height = 0;
}
RETVAL_STRINGL(ImageInfo.Thumbnail.data, ImageInfo.Thumbnail.size);
if ((z_width || z_height) && (!ImageInfo.Thumbnail.width || !ImageInfo.Thumbnail.height)) {
if (!exif_scan_thumbnail(&ImageInfo)) {
ImageInfo.Thumbnail.width = ImageInfo.Thumbnail.height = 0;
}
}
if (z_width) {
ZEND_TRY_ASSIGN_REF_LONG(z_width, ImageInfo.Thumbnail.width);
}
if (z_height) {
ZEND_TRY_ASSIGN_REF_LONG(z_height, ImageInfo.Thumbnail.height);
}
if (arg_c >= 4) {
if (z_imagetype) {
ZEND_TRY_ASSIGN_REF_LONG(z_imagetype, ImageInfo.Thumbnail.filetype);
}

Expand Down
12 changes: 12 additions & 0 deletions ext/exif/tests/exif_thumbnail_streams.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ $fp = fopen(__DIR__ . '/sony.jpg', 'rb');

var_dump(strlen(exif_thumbnail($fp)));

exif_thumbnail($fp, width: $width);
var_dump($width);

exif_thumbnail($fp, height: $height);
var_dump($height);

exif_thumbnail($fp, image_type: $image_type);
var_dump($image_type == IMAGETYPE_JPEG);

fclose($fp);
?>
--EXPECT--
int(4150)
int(160)
int(90)
bool(true)

0 comments on commit 291eef2

Please sign in to comment.