Skip to content

Commit 2998062

Browse files
committed
Image: added and used new functions
1 parent 8d676a4 commit 2998062

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/Utils/Image.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* @method void copyMergeGray(Image $src, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, $opacity)
4848
* @method void copyResampled(Image $src, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH)
4949
* @method void copyResized(Image $src, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH)
50+
* @method Image cropAuto(int $mode = -1, float $threshold = .5, int $color = -1)
5051
* @method void dashedLine($x1, $y1, $x2, $y2, $color)
5152
* @method void ellipse($cx, $cy, $w, $h, $color)
5253
* @method void fill($x, $y, $color)
@@ -56,18 +57,21 @@
5657
* @method void filledRectangle($x1, $y1, $x2, $y2, $color)
5758
* @method void fillToBorder($x, $y, $border, $color)
5859
* @method void filter($filtertype)
60+
* @method void flip(int $mode)
5961
* @method array ftText($size, $angle, $x, $y, $col, string $fontFile, string $text, array $extrainfo = NULL)
6062
* @method void gammaCorrect(float $inputgamma, float $outputgamma)
6163
* @method int interlace($interlace = NULL)
6264
* @method bool isTrueColor()
6365
* @method void layerEffect($effect)
6466
* @method void line($x1, $y1, $x2, $y2, $color)
6567
* @method void paletteCopy(Image $source)
68+
* @method void paletteToTrueColor()
6669
* @method void polygon(array $points, $numPoints, $color)
6770
* @method array psText(string $text, $font, $size, $color, $backgroundColor, $x, $y, $space = NULL, $tightness = NULL, float $angle = NULL, $antialiasSteps = NULL)
6871
* @method void rectangle($x1, $y1, $x2, $y2, $col)
6972
* @method Image rotate(float $angle, $backgroundColor)
7073
* @method void saveAlpha(bool $saveflag)
74+
* @method Image scale(int $newWidth, int $newHeight = -1, int $mode = IMG_BILINEAR_FIXED)
7175
* @method void setBrush(Image $brush)
7276
* @method void setPixel($x, $y, $color)
7377
* @method void setStyle(array $style)
@@ -297,14 +301,8 @@ public function resize($width, $height, $flags = self::FIT)
297301
$this->image = $newImage;
298302
}
299303

300-
if ($width < 0 || $height < 0) { // flip is processed in two steps for better quality
301-
$newImage = static::fromBlank($newWidth, $newHeight, self::RGB(0, 0, 0, 127))->getImageResource();
302-
imagecopyresampled(
303-
$newImage, $this->image,
304-
0, 0, $width < 0 ? $newWidth - 1 : 0, $height < 0 ? $newHeight - 1 : 0,
305-
$newWidth, $newHeight, $width < 0 ? -$newWidth : $newWidth, $height < 0 ? -$newHeight : $newHeight
306-
);
307-
$this->image = $newImage;
304+
if ($width < 0 || $height < 0) {
305+
imageflip($this->image, $width < 0 ? ($height < 0 ? IMG_FLIP_BOTH : IMG_FLIP_HORIZONTAL) : IMG_FLIP_VERTICAL);
308306
}
309307
return $this;
310308
}
@@ -386,10 +384,9 @@ public static function calculateSize($srcWidth, $srcHeight, $newWidth, $newHeigh
386384
*/
387385
public function crop($left, $top, $width, $height)
388386
{
389-
list($left, $top, $width, $height) = static::calculateCutout($this->getWidth(), $this->getHeight(), $left, $top, $width, $height);
390-
$newImage = static::fromBlank($width, $height, self::RGB(0, 0, 0, 127))->getImageResource();
391-
imagecopy($newImage, $this->image, 0, 0, $left, $top, $width, $height);
392-
$this->image = $newImage;
387+
list($rect['x'], $rect['y'], $rect['width'], $rect['height'])
388+
= static::calculateCutout($this->getWidth(), $this->getHeight(), $left, $top, $width, $height);
389+
$this->image = imagecrop($this->image, $rect);
393390
return $this;
394391
}
395392

0 commit comments

Comments
 (0)