Merge pull request #17057 from mauriciofauth/gd-image-wrapper

Wrap GD functions with the `ImageWrapper` class
This commit is contained in:
Maurício Meneghini Fauth 2021-08-07 11:39:05 -03:00 committed by GitHub
commit 3c2d727139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 372 additions and 415 deletions

View File

@ -7,6 +7,7 @@ namespace PhpMyAdmin\Controllers;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\DbTableExists;
use PhpMyAdmin\Image\ImageWrapper;
use PhpMyAdmin\Relation;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
@ -16,14 +17,6 @@ use PhpMyAdmin\Util;
use function __;
use function define;
use function htmlspecialchars;
use function imagecopyresampled;
use function imagecreatefromstring;
use function imagecreatetruecolor;
use function imagedestroy;
use function imagejpeg;
use function imagepng;
use function imagesx;
use function imagesy;
use function in_array;
use function intval;
use function round;
@ -182,13 +175,13 @@ class TransformationWrapperController extends AbstractController
// if image_*__inline.inc.php finds that we can resize,
// it sets the resize parameter to jpeg or png
$srcImage = imagecreatefromstring($row[$transform_key]);
if ($srcImage === false) {
$srcImage = ImageWrapper::fromString($row[$transform_key]);
if ($srcImage === null) {
return;
}
$srcWidth = imagesx($srcImage);
$srcHeight = imagesy($srcImage);
$srcWidth = $srcImage->width();
$srcHeight = $srcImage->height();
// Check to see if the width > height or if width < height
// if so adjust accordingly to make sure the image
@ -206,9 +199,9 @@ class TransformationWrapperController extends AbstractController
}
if ($_REQUEST['resize']) {
$destImage = imagecreatetruecolor($destWidth, $destHeight);
if ($destImage === false) {
imagedestroy($srcImage);
$destImage = ImageWrapper::create($destWidth, $destHeight);
if ($destImage === null) {
$srcImage->destroy();
return;
}
@ -216,8 +209,7 @@ class TransformationWrapperController extends AbstractController
// ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0,
// $destWidth, $destHeight, $srcWidth, $srcHeight);
// better quality but slower:
imagecopyresampled(
$destImage,
$destImage->copyResampled(
$srcImage,
0,
0,
@ -229,17 +221,17 @@ class TransformationWrapperController extends AbstractController
$srcHeight
);
if ($_REQUEST['resize'] === 'jpeg') {
imagejpeg($destImage, null, 75);
$destImage->jpeg(null, 75);
}
if ($_REQUEST['resize'] === 'png') {
imagepng($destImage);
$destImage->png();
}
imagedestroy($destImage);
$destImage->destroy();
}
imagedestroy($srcImage);
$srcImage->destroy();
}
}
}

View File

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Gis;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function explode;
@ -46,19 +47,14 @@ abstract class GisGeometry
* @param string|null $label Label for the GIS POLYGON object
* @param string $color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
* @param resource $image Image object
*
* @return resource the modified image object
*
* @access public
*/
abstract public function prepareRowAsPng(
$spatial,
?string $label,
$color,
array $scale_data,
$image
);
ImageWrapper $image
): ImageWrapper;
/**
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.

View File

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Gis;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function array_merge;
@ -116,14 +117,14 @@ class GisGeometryCollection extends GisGeometry
* @param string|null $label Label for the GIS POLYGON object
* @param string $color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
* @param resource $image Image object
*
* @return resource the modified image object
*
* @access public
*/
public function prepareRowAsPng($spatial, ?string $label, $color, array $scale_data, $image)
{
public function prepareRowAsPng(
$spatial,
?string $label,
$color,
array $scale_data,
ImageWrapper $image
): ImageWrapper {
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
$goem_col = mb_substr($spatial, 19, -1);
// Split the geometry collection object to get its constituents.

View File

@ -7,13 +7,11 @@ declare(strict_types=1);
namespace PhpMyAdmin\Gis;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function count;
use function hexdec;
use function imagecolorallocate;
use function imageline;
use function imagestring;
use function json_encode;
use function mb_substr;
use function trim;
@ -75,57 +73,38 @@ class GisLineString extends GisGeometry
* @param string|null $label Label for the GIS POLYGON object
* @param string $line_color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
* @param resource $image Image object
*
* @return resource the modified image object
*
* @access public
*/
public function prepareRowAsPng(
$spatial,
?string $label,
$line_color,
array $scale_data,
$image
) {
ImageWrapper $image
): ImageWrapper {
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(mb_substr($line_color, 1, 2));
$green = hexdec(mb_substr($line_color, 3, 2));
$blue = hexdec(mb_substr($line_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
$black = $image->colorAllocate(0, 0, 0);
$red = (int) hexdec(mb_substr($line_color, 1, 2));
$green = (int) hexdec(mb_substr($line_color, 3, 2));
$blue = (int) hexdec(mb_substr($line_color, 4, 2));
$color = $image->colorAllocate($red, $green, $blue);
// Trim to remove leading 'LINESTRING(' and trailing ')'
$linesrting = mb_substr($spatial, 11, -1);
$points_arr = $this->extractPoints($linesrting, $scale_data);
$lineString = mb_substr($spatial, 11, -1);
$points_arr = $this->extractPoints($lineString, $scale_data);
foreach ($points_arr as $point) {
if (! isset($temp_point)) {
$temp_point = $point;
} else {
// draw line section
imageline(
$image,
(int) $temp_point[0],
(int) $temp_point[1],
(int) $point[0],
(int) $point[1],
$color
);
$image->line((int) $temp_point[0], (int) $temp_point[1], (int) $point[0], (int) $point[1], $color);
$temp_point = $point;
}
}
// print label if applicable
if (isset($label) && trim($label) != '') {
imagestring(
$image,
1,
$points_arr[1][0],
$points_arr[1][1],
trim($label),
$black
);
$image->string(1, $points_arr[1][0], $points_arr[1][1], trim($label), $black);
}
return $image;

View File

@ -7,14 +7,12 @@ declare(strict_types=1);
namespace PhpMyAdmin\Gis;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function count;
use function explode;
use function hexdec;
use function imagecolorallocate;
use function imageline;
use function imagestring;
use function json_encode;
use function mb_substr;
use function trim;
@ -84,25 +82,20 @@ class GisMultiLineString extends GisGeometry
* @param string|null $label Label for the GIS POLYGON object
* @param string $line_color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
* @param resource $image Image object
*
* @return resource the modified image object
*
* @access public
*/
public function prepareRowAsPng(
$spatial,
?string $label,
$line_color,
array $scale_data,
$image
) {
ImageWrapper $image
): ImageWrapper {
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(mb_substr($line_color, 1, 2));
$green = hexdec(mb_substr($line_color, 3, 2));
$blue = hexdec(mb_substr($line_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
$black = $image->colorAllocate(0, 0, 0);
$red = (int) hexdec(mb_substr($line_color, 1, 2));
$green = (int) hexdec(mb_substr($line_color, 3, 2));
$blue = (int) hexdec(mb_substr($line_color, 4, 2));
$color = $image->colorAllocate($red, $green, $blue);
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
$multilinestirng = mb_substr($spatial, 17, -2);
@ -117,14 +110,7 @@ class GisMultiLineString extends GisGeometry
$temp_point = $point;
} else {
// draw line section
imageline(
$image,
(int) $temp_point[0],
(int) $temp_point[1],
(int) $point[0],
(int) $point[1],
$color
);
$image->line((int) $temp_point[0], (int) $temp_point[1], (int) $point[0], (int) $point[1], $color);
$temp_point = $point;
}
}
@ -132,14 +118,7 @@ class GisMultiLineString extends GisGeometry
unset($temp_point);
// print label if applicable
if (isset($label) && trim($label) != '' && $first_line) {
imagestring(
$image,
1,
$points_arr[1][0],
$points_arr[1][1],
trim($label),
$black
);
$image->string(1, $points_arr[1][0], $points_arr[1][1], trim($label), $black);
}
$first_line = false;

View File

@ -7,13 +7,11 @@ declare(strict_types=1);
namespace PhpMyAdmin\Gis;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function count;
use function hexdec;
use function imagearc;
use function imagecolorallocate;
use function imagestring;
use function json_encode;
use function mb_substr;
use function trim;
@ -75,25 +73,20 @@ class GisMultiPoint extends GisGeometry
* @param string|null $label Label for the GIS POLYGON object
* @param string $point_color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
* @param resource $image Image object
*
* @return resource the modified image object
*
* @access public
*/
public function prepareRowAsPng(
$spatial,
?string $label,
$point_color,
array $scale_data,
$image
) {
ImageWrapper $image
): ImageWrapper {
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(mb_substr($point_color, 1, 2));
$green = hexdec(mb_substr($point_color, 3, 2));
$blue = hexdec(mb_substr($point_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
$black = $image->colorAllocate(0, 0, 0);
$red = (int) hexdec(mb_substr($point_color, 1, 2));
$green = (int) hexdec(mb_substr($point_color, 3, 2));
$blue = (int) hexdec(mb_substr($point_color, 4, 2));
$color = $image->colorAllocate($red, $green, $blue);
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
$multipoint = mb_substr($spatial, 11, -1);
@ -105,7 +98,7 @@ class GisMultiPoint extends GisGeometry
continue;
}
imagearc($image, (int) $point[0], (int) $point[1], 7, 7, 0, 360, $color);
$image->arc((int) $point[0], (int) $point[1], 7, 7, 0, 360, $color);
}
// print label for each point
@ -113,14 +106,7 @@ class GisMultiPoint extends GisGeometry
(isset($label) && trim($label) != '')
&& ($points_arr[0][0] != '' && $points_arr[0][1] != '')
) {
imagestring(
$image,
1,
$points_arr[0][0],
$points_arr[0][1],
trim($label),
$black
);
$image->string(1, $points_arr[0][0], $points_arr[0][1], trim($label), $black);
}
return $image;

View File

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Gis;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function array_merge;
@ -15,9 +16,6 @@ use function array_slice;
use function count;
use function explode;
use function hexdec;
use function imagecolorallocate;
use function imagefilledpolygon;
use function imagestring;
use function json_encode;
use function mb_substr;
use function str_contains;
@ -97,25 +95,20 @@ class GisMultiPolygon extends GisGeometry
* @param string|null $label Label for the GIS POLYGON object
* @param string $fill_color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
* @param resource $image Image object
*
* @return resource the modified image object
*
* @access public
*/
public function prepareRowAsPng(
$spatial,
?string $label,
$fill_color,
array $scale_data,
$image
) {
ImageWrapper $image
): ImageWrapper {
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(mb_substr($fill_color, 1, 2));
$green = hexdec(mb_substr($fill_color, 3, 2));
$blue = hexdec(mb_substr($fill_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
$black = $image->colorAllocate(0, 0, 0);
$red = (int) hexdec(mb_substr($fill_color, 1, 2));
$green = (int) hexdec(mb_substr($fill_color, 3, 2));
$blue = (int) hexdec(mb_substr($fill_color, 4, 2));
$color = $image->colorAllocate($red, $green, $blue);
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
$multipolygon = mb_substr($spatial, 15, -3);
@ -145,7 +138,7 @@ class GisMultiPolygon extends GisGeometry
}
// draw polygon
imagefilledpolygon($image, $points_arr, count($points_arr) / 2, $color);
$image->filledPolygon($points_arr, count($points_arr) / 2, $color);
// mark label point if applicable
if (isset($label) && trim($label) != '' && $first_poly) {
$label_point = [
@ -159,14 +152,7 @@ class GisMultiPolygon extends GisGeometry
// print label if applicable
if (isset($label_point)) {
imagestring(
$image,
1,
$points_arr[2],
$points_arr[3],
trim((string) $label),
$black
);
$image->string(1, $points_arr[2], $points_arr[3], trim((string) $label), $black);
}
return $image;

View File

@ -7,12 +7,10 @@ declare(strict_types=1);
namespace PhpMyAdmin\Gis;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function hexdec;
use function imagearc;
use function imagecolorallocate;
use function imagestring;
use function json_encode;
use function mb_substr;
use function trim;
@ -74,25 +72,20 @@ class GisPoint extends GisGeometry
* @param string|null $label Label for the GIS POLYGON object
* @param string $point_color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
* @param resource $image Image object
*
* @return resource the modified image object
*
* @access public
*/
public function prepareRowAsPng(
$spatial,
?string $label,
$point_color,
array $scale_data,
$image
) {
ImageWrapper $image
): ImageWrapper {
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(mb_substr($point_color, 1, 2));
$green = hexdec(mb_substr($point_color, 3, 2));
$blue = hexdec(mb_substr($point_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
$black = $image->colorAllocate(0, 0, 0);
$red = (int) hexdec(mb_substr($point_color, 1, 2));
$green = (int) hexdec(mb_substr($point_color, 3, 2));
$blue = (int) hexdec(mb_substr($point_color, 4, 2));
$color = $image->colorAllocate($red, $green, $blue);
// Trim to remove leading 'POINT(' and trailing ')'
$point = mb_substr($spatial, 6, -1);
@ -100,26 +93,10 @@ class GisPoint extends GisGeometry
// draw a small circle to mark the point
if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
imagearc(
$image,
(int) $points_arr[0][0],
(int) $points_arr[0][1],
7,
7,
0,
360,
$color
);
$image->arc((int) $points_arr[0][0], (int) $points_arr[0][1], 7, 7, 0, 360, $color);
// print label if applicable
if (isset($label) && trim($label) != '') {
imagestring(
$image,
1,
$points_arr[0][0],
$points_arr[0][1],
trim($label),
$black
);
$image->string(1, $points_arr[0][0], $points_arr[0][1], trim($label), $black);
}
}

View File

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Gis;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function array_merge;
@ -15,9 +16,6 @@ use function array_slice;
use function count;
use function explode;
use function hexdec;
use function imagecolorallocate;
use function imagefilledpolygon;
use function imagestring;
use function json_encode;
use function max;
use function mb_substr;
@ -93,25 +91,20 @@ class GisPolygon extends GisGeometry
* @param string|null $label Label for the GIS POLYGON object
* @param string $fill_color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
* @param resource $image Image object
*
* @return resource the modified image object
*
* @access public
*/
public function prepareRowAsPng(
$spatial,
?string $label,
$fill_color,
array $scale_data,
$image
) {
ImageWrapper $image
): ImageWrapper {
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(mb_substr($fill_color, 1, 2));
$green = hexdec(mb_substr($fill_color, 3, 2));
$blue = hexdec(mb_substr($fill_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
$black = $image->colorAllocate(0, 0, 0);
$red = (int) hexdec(mb_substr($fill_color, 1, 2));
$green = (int) hexdec(mb_substr($fill_color, 3, 2));
$blue = (int) hexdec(mb_substr($fill_color, 4, 2));
$color = $image->colorAllocate($red, $green, $blue);
// Trim to remove leading 'POLYGON((' and trailing '))'
$polygon = mb_substr($spatial, 9, -2);
@ -136,17 +129,10 @@ class GisPolygon extends GisGeometry
}
// draw polygon
imagefilledpolygon($image, $points_arr, count($points_arr) / 2, $color);
$image->filledPolygon($points_arr, count($points_arr) / 2, $color);
// print label if applicable
if (isset($label) && trim($label) != '') {
imagestring(
$image,
1,
$points_arr[2],
$points_arr[3],
trim($label),
$black
);
$image->string(1, $points_arr[2], $points_arr[3], trim($label), $black);
}
return $image;

View File

@ -8,6 +8,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Gis;
use PhpMyAdmin\Core;
use PhpMyAdmin\Image\ImageWrapper;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Util;
use TCPDF;
@ -15,11 +16,6 @@ use TCPDF;
use function array_merge;
use function base64_encode;
use function count;
use function imagecolorallocate;
use function imagecreatetruecolor;
use function imagedestroy;
use function imagefilledrectangle;
use function imagepng;
use function intval;
use function is_numeric;
use function is_string;
@ -400,32 +396,25 @@ class GisVisualization
/**
* Generate the visualization in PNG format.
*
* @return resource the generated image resource
* @return ImageWrapper|null the generated image resource
*
* @access private
*/
private function png()
private function png(): ?ImageWrapper
{
$this->init();
// create image
$image = imagecreatetruecolor(
$image = ImageWrapper::create(
$this->settings['width'],
$this->settings['height']
);
// fill the background
$bg = imagecolorallocate($image, 229, 229, 229);
imagefilledrectangle(
$image,
0,
0,
$this->settings['width'] - 1,
$this->settings['height'] - 1,
$bg
$this->settings['height'],
['red' => 229, 'green' => 229, 'blue' => 229]
);
if ($image === null) {
return null;
}
$scale_data = $this->scaleDataSet($this->data);
/** @var ImageWrapper $image */
$image = $this->prepareDataSet($this->data, $scale_data, 'png', $image);
return $image;
@ -440,12 +429,15 @@ class GisVisualization
*/
public function asPng()
{
$img = $this->png();
$image = $this->png();
if ($image === null) {
return '';
}
// render and save it to variable
ob_start();
imagepng($img, null, 9, PNG_ALL_FILTERS);
imagedestroy($img);
$image->png(null, 9, PNG_ALL_FILTERS);
$image->destroy();
$output = ob_get_clean();
// base64 encode
@ -458,17 +450,17 @@ class GisVisualization
* Saves as a PNG image to a file.
*
* @param string $file_name File name
*
* @return void
*
* @access public
*/
public function toFileAsPng($file_name)
public function toFileAsPng($file_name): void
{
$img = $this->png();
$image = $this->png();
if ($image === null) {
return;
}
$this->writeToFile($file_name, 'image/png', 'png');
imagepng($img, null, 9, PNG_ALL_FILTERS);
imagedestroy($img);
$image->png(null, 9, PNG_ALL_FILTERS);
$image->destroy();
}
/**
@ -700,11 +692,11 @@ class GisVisualization
/**
* Prepares and return the dataset as needed by the visualization.
*
* @param array $data Raw data
* @param array $scale_data Data related to scaling
* @param string $format Format of the visualization
* @param resource|TCPDF|string|false $results Image object in the case of png
* TCPDF object in the case of pdf
* @param array $data Raw data
* @param array $scale_data Data related to scaling
* @param string $format Format of the visualization
* @param ImageWrapper|TCPDF|string|false $results Image object in the case of png
* TCPDF object in the case of pdf
*
* @return mixed the formatted array of data
*

View File

@ -0,0 +1,183 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Image;
use function extension_loaded;
use function imagearc;
use function imagecolorallocate;
use function imagecopyresampled;
use function imagecreatefromstring;
use function imagecreatetruecolor;
use function imagedestroy;
use function imagefilledpolygon;
use function imagefilledrectangle;
use function imagejpeg;
use function imageline;
use function imagepng;
use function imagestring;
use function imagesx;
use function imagesy;
final class ImageWrapper
{
/** @var resource */
private $image;
/**
* @param resource $image
*/
private function __construct($image)
{
$this->image = $image;
}
/**
* @return resource
*/
public function getImage()
{
return $this->image;
}
/**
* @param array<string, int>|null $background
* @psalm-param array{red: int, green: int, blue: int} $background
*/
public static function create(int $width, int $height, ?array $background = null): ?self
{
if (! extension_loaded('gd')) {
return null;
}
$image = imagecreatetruecolor($width, $height);
if ($image === false) {
return null;
}
if (! isset($background, $background['red'], $background['green'], $background['blue'])) {
return new self($image);
}
$backgroundColor = imagecolorallocate($image, $background['red'], $background['green'], $background['blue']);
if ($backgroundColor === false) {
imagedestroy($image);
return null;
}
if (! imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $backgroundColor)) {
imagedestroy($image);
return null;
}
return new self($image);
}
public static function fromString(string $data): ?self
{
if (! extension_loaded('gd')) {
return null;
}
$image = imagecreatefromstring($data);
if ($image === false) {
return null;
}
return new self($image);
}
public function arc(
int $centerX,
int $centerY,
int $width,
int $height,
int $startAngle,
int $endAngle,
int $color
): bool {
return imagearc($this->image, $centerX, $centerY, $width, $height, $startAngle, $endAngle, $color);
}
/**
* @return int|false
*/
public function colorAllocate(int $red, int $green, int $blue)
{
return imagecolorallocate($this->image, $red, $green, $blue);
}
public function copyResampled(
ImageWrapper $sourceImage,
int $destinationX,
int $destinationY,
int $sourceX,
int $sourceY,
int $destinationWidth,
int $destinationHeight,
int $sourceWidth,
int $sourceHeight
): bool {
return imagecopyresampled(
$this->image,
$sourceImage->getImage(),
$destinationX,
$destinationY,
$sourceX,
$sourceY,
$destinationWidth,
$destinationHeight,
$sourceWidth,
$sourceHeight
);
}
public function destroy(): bool
{
return imagedestroy($this->image);
}
public function filledPolygon(array $points, int $numPoints, int $color): bool
{
return imagefilledpolygon($this->image, $points, $numPoints, $color);
}
public function height(): int
{
return imagesy($this->image);
}
/**
* @param resource|string|null $file
*/
public function jpeg($file = null, int $quality = -1): bool
{
return imagejpeg($this->image, $file, $quality);
}
public function line(int $x1, int $y1, int $x2, int $y2, int $color): bool
{
return imageline($this->image, $x1, $y1, $x2, $y2, $color);
}
/**
* @param resource|string|null $file
*/
public function png($file = null, int $quality = -1, int $filters = -1): bool
{
return imagepng($this->image, $file, $quality, $filters);
}
public function string(int $font, int $x, int $y, string $string, int $color): bool
{
return imagestring($this->image, $font, $x, $y, $string, $color);
}
public function width(): int
{
return imagesx($this->image);
}
}

View File

@ -365,33 +365,18 @@ parameters:
count: 1
path: libraries/classes/Gis/GisLineString.php
-
message: "#^Parameter \\#2 \\$red of function imagecolorallocate expects int, float\\|int given\\.$#"
count: 1
path: libraries/classes/Gis/GisLineString.php
-
message: "#^Parameter \\#2 \\$srid of method PhpMyAdmin\\\\Gis\\\\GisGeometry\\:\\:getLineForOpenLayers\\(\\) expects string, int given\\.$#"
count: 1
path: libraries/classes/Gis/GisLineString.php
-
message: "#^Parameter \\#3 \\$green of function imagecolorallocate expects int, float\\|int given\\.$#"
message: "#^Parameter \\#5 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:line\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisLineString.php
-
message: "#^Parameter \\#4 \\$blue of function imagecolorallocate expects int, float\\|int given\\.$#"
count: 1
path: libraries/classes/Gis/GisLineString.php
-
message: "#^Parameter \\#6 \\$col of function imageline expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisLineString.php
-
message: "#^Parameter \\#6 \\$col of function imagestring expects int, int\\|false given\\.$#"
message: "#^Parameter \\#5 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:string\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisLineString.php
@ -400,33 +385,18 @@ parameters:
count: 1
path: libraries/classes/Gis/GisMultiLineString.php
-
message: "#^Parameter \\#2 \\$red of function imagecolorallocate expects int, float\\|int given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiLineString.php
-
message: "#^Parameter \\#2 \\$srid of method PhpMyAdmin\\\\Gis\\\\GisGeometry\\:\\:getLineArrayForOpenLayers\\(\\) expects string, int given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiLineString.php
-
message: "#^Parameter \\#3 \\$green of function imagecolorallocate expects int, float\\|int given\\.$#"
message: "#^Parameter \\#5 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:line\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiLineString.php
-
message: "#^Parameter \\#4 \\$blue of function imagecolorallocate expects int, float\\|int given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiLineString.php
-
message: "#^Parameter \\#6 \\$col of function imageline expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiLineString.php
-
message: "#^Parameter \\#6 \\$col of function imagestring expects int, int\\|false given\\.$#"
message: "#^Parameter \\#5 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:string\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiLineString.php
@ -435,33 +405,18 @@ parameters:
count: 1
path: libraries/classes/Gis/GisMultiPoint.php
-
message: "#^Parameter \\#2 \\$red of function imagecolorallocate expects int, float\\|int given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPoint.php
-
message: "#^Parameter \\#2 \\$srid of method PhpMyAdmin\\\\Gis\\\\GisMultiPoint\\:\\:getPointsArrayForOpenLayers\\(\\) expects string, int given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPoint.php
-
message: "#^Parameter \\#3 \\$green of function imagecolorallocate expects int, float\\|int given\\.$#"
message: "#^Parameter \\#5 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:string\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPoint.php
-
message: "#^Parameter \\#4 \\$blue of function imagecolorallocate expects int, float\\|int given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPoint.php
-
message: "#^Parameter \\#6 \\$col of function imagestring expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPoint.php
-
message: "#^Parameter \\#8 \\$col of function imagearc expects int, int\\|false given\\.$#"
message: "#^Parameter \\#7 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:arc\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPoint.php
@ -470,33 +425,18 @@ parameters:
count: 1
path: libraries/classes/Gis/GisMultiPolygon.php
-
message: "#^Parameter \\#2 \\$red of function imagecolorallocate expects int, float\\|int given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPolygon.php
-
message: "#^Parameter \\#2 \\$srid of method PhpMyAdmin\\\\Gis\\\\GisGeometry\\:\\:getPolygonArrayForOpenLayers\\(\\) expects string, int given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPolygon.php
-
message: "#^Parameter \\#3 \\$green of function imagecolorallocate expects int, float\\|int given\\.$#"
message: "#^Parameter \\#3 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:filledPolygon\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPolygon.php
-
message: "#^Parameter \\#4 \\$blue of function imagecolorallocate expects int, float\\|int given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPolygon.php
-
message: "#^Parameter \\#4 \\$col of function imagefilledpolygon expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPolygon.php
-
message: "#^Parameter \\#6 \\$col of function imagestring expects int, int\\|false given\\.$#"
message: "#^Parameter \\#5 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:string\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisMultiPolygon.php
@ -505,33 +445,18 @@ parameters:
count: 1
path: libraries/classes/Gis/GisPoint.php
-
message: "#^Parameter \\#2 \\$red of function imagecolorallocate expects int, float\\|int given\\.$#"
count: 1
path: libraries/classes/Gis/GisPoint.php
-
message: "#^Parameter \\#2 \\$srid of method PhpMyAdmin\\\\Gis\\\\GisGeometry\\:\\:getPointForOpenLayers\\(\\) expects string, int given\\.$#"
count: 1
path: libraries/classes/Gis/GisPoint.php
-
message: "#^Parameter \\#3 \\$green of function imagecolorallocate expects int, float\\|int given\\.$#"
message: "#^Parameter \\#5 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:string\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisPoint.php
-
message: "#^Parameter \\#4 \\$blue of function imagecolorallocate expects int, float\\|int given\\.$#"
count: 1
path: libraries/classes/Gis/GisPoint.php
-
message: "#^Parameter \\#6 \\$col of function imagestring expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisPoint.php
-
message: "#^Parameter \\#8 \\$col of function imagearc expects int, int\\|false given\\.$#"
message: "#^Parameter \\#7 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:arc\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisPoint.php
@ -540,46 +465,21 @@ parameters:
count: 1
path: libraries/classes/Gis/GisPolygon.php
-
message: "#^Parameter \\#2 \\$red of function imagecolorallocate expects int, float\\|int given\\.$#"
count: 1
path: libraries/classes/Gis/GisPolygon.php
-
message: "#^Parameter \\#2 \\$srid of method PhpMyAdmin\\\\Gis\\\\GisGeometry\\:\\:getPolygonForOpenLayers\\(\\) expects string, int given\\.$#"
count: 1
path: libraries/classes/Gis/GisPolygon.php
-
message: "#^Parameter \\#3 \\$green of function imagecolorallocate expects int, float\\|int given\\.$#"
message: "#^Parameter \\#3 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:filledPolygon\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisPolygon.php
-
message: "#^Parameter \\#4 \\$blue of function imagecolorallocate expects int, float\\|int given\\.$#"
message: "#^Parameter \\#5 \\$color of method PhpMyAdmin\\\\Image\\\\ImageWrapper\\:\\:string\\(\\) expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisPolygon.php
-
message: "#^Parameter \\#4 \\$col of function imagefilledpolygon expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisPolygon.php
-
message: "#^Parameter \\#6 \\$col of function imagestring expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisPolygon.php
-
message: "#^Parameter \\#1 \\$im of function imagecolorallocate expects resource, resource\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisVisualization.php
-
message: "#^Parameter \\#1 \\$im of function imagefilledrectangle expects resource, resource\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisVisualization.php
-
message: "#^Parameter \\#1 \\$sql_query of class PhpMyAdmin\\\\Gis\\\\GisVisualization constructor expects string, null given\\.$#"
count: 1
@ -595,11 +495,6 @@ parameters:
count: 1
path: libraries/classes/Gis/GisVisualization.php
-
message: "#^Parameter \\#6 \\$col of function imagefilledrectangle expects int, int\\|false given\\.$#"
count: 1
path: libraries/classes/Gis/GisVisualization.php
-
message: "#^Cannot access offset 1 on array\\|false\\.$#"
count: 2

View File

@ -8223,6 +8223,10 @@
<code>$line_color</code>
<code>$line_color</code>
</ParamNameMismatch>
<PossiblyFalseArgument occurrences="2">
<code>$black</code>
<code>$color</code>
</PossiblyFalseArgument>
<RedundantPropertyInitializationCheck occurrences="1">
<code>isset(self::$instance)</code>
</RedundantPropertyInitializationCheck>
@ -8302,6 +8306,10 @@
<code>$line_color</code>
<code>$line_color</code>
</ParamNameMismatch>
<PossiblyFalseArgument occurrences="2">
<code>$black</code>
<code>$color</code>
</PossiblyFalseArgument>
<RedundantPropertyInitializationCheck occurrences="1">
<code>isset(self::$instance)</code>
</RedundantPropertyInitializationCheck>
@ -8374,6 +8382,10 @@
<code>$point_color</code>
<code>$point_color</code>
</ParamNameMismatch>
<PossiblyFalseArgument occurrences="2">
<code>$black</code>
<code>$color</code>
</PossiblyFalseArgument>
<RedundantPropertyInitializationCheck occurrences="1">
<code>isset(self::$instance)</code>
</RedundantPropertyInitializationCheck>
@ -8497,6 +8509,10 @@
<code>$fill_color</code>
<code>$fill_color</code>
</ParamNameMismatch>
<PossiblyFalseArgument occurrences="2">
<code>$black</code>
<code>$color</code>
</PossiblyFalseArgument>
<PossiblyInvalidArgument occurrences="1">
<code>count($points_arr) / 2</code>
</PossiblyInvalidArgument>
@ -8563,6 +8579,10 @@
<code>$point_color</code>
<code>$point_color</code>
</ParamNameMismatch>
<PossiblyFalseArgument occurrences="2">
<code>$black</code>
<code>$color</code>
</PossiblyFalseArgument>
<RedundantPropertyInitializationCheck occurrences="1">
<code>isset(self::$instance)</code>
</RedundantPropertyInitializationCheck>
@ -8708,6 +8728,10 @@
<code>$fill_color</code>
<code>$fill_color</code>
</ParamNameMismatch>
<PossiblyFalseArgument occurrences="2">
<code>$black</code>
<code>$color</code>
</PossiblyFalseArgument>
<PossiblyInvalidArgument occurrences="1">
<code>count($points_arr) / 2</code>
</PossiblyInvalidArgument>
@ -8737,7 +8761,7 @@
<DocblockTypeContradiction occurrences="1">
<code>$this-&gt;userSpecifiedSettings === null</code>
</DocblockTypeContradiction>
<MixedArgument occurrences="24">
<MixedArgument occurrences="22">
<code>$label</code>
<code>$label</code>
<code>$label</code>
@ -8755,9 +8779,7 @@
<code>$this-&gt;settings['colors'][$index]</code>
<code>$this-&gt;settings['colors_hex'][$index]</code>
<code>$this-&gt;settings['height']</code>
<code>$this-&gt;settings['height'] - 1</code>
<code>$this-&gt;settings['width']</code>
<code>$this-&gt;settings['width'] - 1</code>
<code>$this-&gt;userSpecifiedSettings['labelColumn']</code>
<code>$this-&gt;userSpecifiedSettings['spatialColumn']</code>
<code>$this-&gt;userSpecifiedSettings['spatialColumn']</code>
@ -8791,8 +8813,7 @@
<code>$row[$this-&gt;settings['spatialColumn']]</code>
<code>$row[$this-&gt;settings['spatialColumn']]</code>
</MixedArrayOffset>
<MixedAssignment occurrences="19">
<code>$image</code>
<MixedAssignment occurrences="18">
<code>$label</code>
<code>$modified_result</code>
<code>$pdf</code>
@ -8812,13 +8833,10 @@
<code>$y</code>
<code>$y_ratio</code>
</MixedAssignment>
<MixedInferredReturnType occurrences="1">
<code>resource</code>
</MixedInferredReturnType>
<MixedMethodCall occurrences="1">
<code>Output</code>
</MixedMethodCall>
<MixedOperand occurrences="23">
<MixedOperand occurrences="21">
<code>$border / $scale</code>
<code>$border / $scale</code>
<code>$min_max['maxX'] + $min_max['minX'] - $plot_width / $scale</code>
@ -8833,17 +8851,12 @@
<code>$this-&gt;prepareDataSet($this-&gt;data, $scale_data, 'ol', '')</code>
<code>$this-&gt;prepareDataSet($this-&gt;data, $scale_data, 'svg', '')</code>
<code>$this-&gt;settings['height']</code>
<code>$this-&gt;settings['height']</code>
<code>$this-&gt;settings['width']</code>
<code>$this-&gt;settings['width']</code>
<code>Util::backquote($this-&gt;userSpecifiedSettings['spatialColumn'])</code>
<code>Util::backquote($this-&gt;userSpecifiedSettings['spatialColumn'])</code>
<code>Util::backquote('srid')</code>
<code>Util::backquote('temp_gis')</code>
</MixedOperand>
<MixedReturnStatement occurrences="1">
<code>$image</code>
</MixedReturnStatement>
<NullArgument occurrences="3">
<code>null</code>
<code>null</code>

View File

@ -11,8 +11,6 @@ use PhpMyAdmin\Gis\GisGeometry;
use PhpMyAdmin\Gis\GisPolygon;
use PhpMyAdmin\Tests\AbstractTestCase;
use function imagesx;
/**
* Abstract parent class for all Gis<Geom_type> test classes
*/
@ -64,14 +62,4 @@ abstract class GisGeomTestCase extends AbstractTestCase
$this->object->scaleRow($spatial)
);
}
/**
* Tests whether content is a valid image.
*
* @param resource $object Image
*/
public function assertImage($object): void
{
$this->assertGreaterThan(0, imagesx($object));
}
}

View File

@ -5,13 +5,11 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Gis;
use PhpMyAdmin\Gis\GisGeometryCollection;
use PhpMyAdmin\Image\ImageWrapper;
use PhpMyAdmin\Tests\AbstractTestCase;
use TCPDF;
use function function_exists;
use function imagecreatetruecolor;
use function imagesx;
use function imagesy;
use function method_exists;
use function preg_match;
@ -184,8 +182,8 @@ class GisGeometryCollectionTest extends AbstractTestCase
$this->markTestSkipped('GD extension missing!');
}
$image = imagecreatetruecolor(120, 150);
$this->assertNotFalse($image);
$image = ImageWrapper::create(120, 150);
$this->assertNotNull($image);
$return = $this->object->prepareRowAsPng(
'GEOMETRYCOLLECTION(POLYGON((35 10,10 20,15 40,45 45,35 10),'
. '(20 30,35 32,30 20,20 30)))',
@ -194,8 +192,8 @@ class GisGeometryCollectionTest extends AbstractTestCase
['x' => 12, 'y' => 69, 'scale' => 2, 'height' => 150],
$image
);
$this->assertEquals(120, imagesx($return));
$this->assertEquals(150, imagesy($return));
$this->assertEquals(120, $return->width());
$this->assertEquals(150, $return->height());
}
/**

View File

@ -5,10 +5,10 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Gis;
use PhpMyAdmin\Gis\GisLineString;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function function_exists;
use function imagecreatetruecolor;
use function preg_match;
/**
@ -177,8 +177,8 @@ class GisLineStringTest extends GisGeomTestCase
$this->markTestSkipped('GD extension missing!');
}
$image = imagecreatetruecolor(120, 150);
$this->assertNotFalse($image);
$image = ImageWrapper::create(120, 150);
$this->assertNotNull($image);
$return = $this->object->prepareRowAsPng(
'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
'image',
@ -186,7 +186,8 @@ class GisLineStringTest extends GisGeomTestCase
['x' => 12, 'y' => 69, 'scale' => 2, 'height' => 150],
$image
);
$this->assertImage($return);
$this->assertEquals(120, $return->width());
$this->assertEquals(150, $return->height());
}
/**

View File

@ -5,10 +5,10 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Gis;
use PhpMyAdmin\Gis\GisMultiLineString;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function function_exists;
use function imagecreatetruecolor;
use function preg_match;
/**
@ -259,8 +259,8 @@ class GisMultiLineStringTest extends GisGeomTestCase
$this->markTestSkipped('GD extension missing!');
}
$image = imagecreatetruecolor(120, 150);
$this->assertNotFalse($image);
$image = ImageWrapper::create(120, 150);
$this->assertNotNull($image);
$return = $this->object->prepareRowAsPng(
'MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))',
'image',
@ -268,7 +268,8 @@ class GisMultiLineStringTest extends GisGeomTestCase
['x' => 12, 'y' => 69, 'scale' => 2, 'height' => 150],
$image
);
$this->assertImage($return);
$this->assertEquals(120, $return->width());
$this->assertEquals(150, $return->height());
}
/**

View File

@ -5,10 +5,10 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Gis;
use PhpMyAdmin\Gis\GisMultiPoint;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function function_exists;
use function imagecreatetruecolor;
use function preg_match;
/**
@ -179,8 +179,8 @@ class GisMultiPointTest extends GisGeomTestCase
$this->markTestSkipped('GD extension missing!');
}
$image = imagecreatetruecolor(120, 150);
$this->assertNotFalse($image);
$image = ImageWrapper::create(120, 150);
$this->assertNotNull($image);
$return = $this->object->prepareRowAsPng(
'MULTIPOINT(12 35,48 75,69 23,25 45,14 53,35 78)',
'image',
@ -188,7 +188,8 @@ class GisMultiPointTest extends GisGeomTestCase
['x' => 12, 'y' => 69, 'scale' => 2, 'height' => 150],
$image
);
$this->assertImage($return);
$this->assertEquals(120, $return->width());
$this->assertEquals(150, $return->height());
}
/**

View File

@ -5,10 +5,10 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Gis;
use PhpMyAdmin\Gis\GisMultiPolygon;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function function_exists;
use function imagecreatetruecolor;
use function preg_match;
/**
@ -346,8 +346,8 @@ class GisMultiPolygonTest extends GisGeomTestCase
$this->markTestSkipped('GD extension missing!');
}
$image = imagecreatetruecolor(120, 150);
$this->assertNotFalse($image);
$image = ImageWrapper::create(120, 150);
$this->assertNotNull($image);
$return = $this->object->prepareRowAsPng(
'MULTIPOLYGON(((136 40,147 83,16 75,136 40)),'
. '((105 0,56 20,78 73,105 0)))',
@ -356,7 +356,8 @@ class GisMultiPolygonTest extends GisGeomTestCase
['x' => 12, 'y' => 69, 'scale' => 2, 'height' => 150],
$image
);
$this->assertImage($return);
$this->assertEquals(120, $return->width());
$this->assertEquals(150, $return->height());
}
/**

View File

@ -5,10 +5,10 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Gis;
use PhpMyAdmin\Gis\GisPoint;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function function_exists;
use function imagecreatetruecolor;
/**
* @covers \PhpMyAdmin\Gis\GisPoint
@ -194,8 +194,8 @@ class GisPointTest extends GisGeomTestCase
$this->markTestSkipped('GD extension missing!');
}
$image = imagecreatetruecolor(120, 150);
$this->assertNotFalse($image);
$image = ImageWrapper::create(120, 150);
$this->assertNotNull($image);
$return = $this->object->prepareRowAsPng(
'POINT(12 35)',
'image',
@ -203,7 +203,8 @@ class GisPointTest extends GisGeomTestCase
['x' => 12, 'y' => 69, 'scale' => 2, 'height' => 150],
$image
);
$this->assertImage($return);
$this->assertEquals(120, $return->width());
$this->assertEquals(150, $return->height());
}
/**

View File

@ -5,10 +5,10 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Gis;
use PhpMyAdmin\Gis\GisPolygon;
use PhpMyAdmin\Image\ImageWrapper;
use TCPDF;
use function function_exists;
use function imagecreatetruecolor;
use function preg_match;
/**
@ -432,8 +432,8 @@ class GisPolygonTest extends GisGeomTestCase
$this->markTestSkipped('GD extension missing!');
}
$image = imagecreatetruecolor(120, 150);
$this->assertNotFalse($image);
$image = ImageWrapper::create(120, 150);
$this->assertNotNull($image);
$return = $this->object->prepareRowAsPng(
'POLYGON((123 0,23 30,17 63,123 0))',
'image',
@ -441,7 +441,8 @@ class GisPolygonTest extends GisGeomTestCase
['x' => 12, 'y' => 69, 'scale' => 2, 'height' => 150],
$image
);
$this->assertImage($return);
$this->assertEquals(120, $return->width());
$this->assertEquals(150, $return->height());
}
/**