Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 39 additions & 0 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,12 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagesetinterpolation, 0)
ZEND_ARG_INFO(0, method)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_imageresolution, 0, 0, 1)
ZEND_ARG_INFO(0, im)
ZEND_ARG_INFO(0, res_x)
ZEND_ARG_INFO(0, res_y)
ZEND_END_ARG_INFO()

/* }}} */

/* {{{ gd_functions[]
Expand Down Expand Up @@ -965,6 +971,8 @@ const zend_function_entry gd_functions[] = {
PHP_FE(imagefilter, arginfo_imagefilter)
PHP_FE(imageconvolution, arginfo_imageconvolution)

PHP_FE(imageresolution, arginfo_imageresolution)

PHP_FE_END
};
/* }}} */
Expand Down Expand Up @@ -4991,6 +4999,37 @@ PHP_FUNCTION(imagesetinterpolation)
}
/* }}} */

/* {{{ proto array imageresolution(resource im [, res_x, [res_y]])
Get or set the resolution of the image in DPI. */
PHP_FUNCTION(imageresolution)
{
zval *IM;
gdImagePtr im;
zend_long res_x = GD_RESOLUTION, res_y = GD_RESOLUTION;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|ll", &IM, &res_x, &res_y) == FAILURE) {
return;
}

if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) {
RETURN_FALSE;
}

switch (ZEND_NUM_ARGS()) {
case 3:
gdImageSetResolution(im, res_x, res_y);
RETURN_TRUE;
case 2:
gdImageSetResolution(im, res_x, res_x);
RETURN_TRUE;
default:
array_init(return_value);
add_next_index_long(return_value, gdImageResolutionX(im));
add_next_index_long(return_value, gdImageResolutionY(im));
}
}
/* }}} */

/*
* Local variables:
* tab-width: 4
Expand Down
2 changes: 2 additions & 0 deletions ext/gd/php_gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ PHP_FUNCTION(imagexbm);
PHP_FUNCTION(imagefilter);
PHP_FUNCTION(imageconvolution);

PHP_FUNCTION(imageresolution);

PHP_GD_API int phpi_get_le_gd(void);

#else
Expand Down
43 changes: 43 additions & 0 deletions ext/gd/tests/imageresolution_jpeg.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
Set and get image resolution of JPEG images
--SKIPIF--
<?php
if (!extension_loaded('gd')) die('skip gd extension not available');
if (!(imagetypes() & IMG_JPEG)) die('skip JPEG support not available');
?>
--FILE--
<?php
$filename = __DIR__ . DIRECTORY_SEPARATOR . 'imageresolution_jpeg.jpeg';

$exp = imagecreate(100, 100);
imagecolorallocate($exp, 255, 0, 0);

imageresolution($exp, 71);
imagejpeg($exp, $filename);
$act = imagecreatefromjpeg($filename);
var_dump(imageresolution($act));

imageresolution($exp, 71, 299);
imagejpeg($exp, $filename);
$act = imagecreatefromjpeg($filename);
var_dump(imageresolution($act));
?>
===DONE===
--EXPECT--
array(2) {
[0]=>
int(71)
[1]=>
int(71)
}
array(2) {
[0]=>
int(71)
[1]=>
int(299)
}
===DONE===
--CLEAN--
<?php
@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'imageresolution_jpeg.jpeg');
?>
42 changes: 42 additions & 0 deletions ext/gd/tests/imageresolution_png.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
Set and get image resolution of PNG images
--SKIPIF--
<?php
if (!extension_loaded('gd')) die('skip gd extension not available');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first test has a skip for supported image type, this one doesn't. Is there a reason for that ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PNG is always supported; JPEG only when requested during build time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's perfectly sensible. I wasn't sure, and did look for other tests checking for png, did find only one. Must be anomalous (maybe fix that when you have a moment).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with 371f412.

?>
--FILE--
<?php
$filename = __DIR__ . DIRECTORY_SEPARATOR . 'imageresolution_png.png';

$exp = imagecreate(100, 100);
imagecolorallocate($exp, 255, 0, 0);

imageresolution($exp, 71);
imagepng($exp, $filename);
$act = imagecreatefrompng($filename);
var_dump(imageresolution($act));

imageresolution($exp, 71, 299);
imagepng($exp, $filename);
$act = imagecreatefrompng($filename);
var_dump(imageresolution($act));
?>
===DONE===
--EXPECT--
array(2) {
[0]=>
int(71)
[1]=>
int(71)
}
array(2) {
[0]=>
int(71)
[1]=>
int(299)
}
===DONE===
--CLEAN--
<?php
@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'imageresolution_png.png');
?>