Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

Commit

Permalink
Fixed cropped and resized PNGs
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Apr 4, 2014
1 parent a92fca0 commit 1fd8799
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
slirconfig.class.php
slirconfig.class.php
cache
42 changes: 35 additions & 7 deletions core/libs/gd/slirgdimage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class SLIRGDImage extends SLIRImage implements SLIRImageLibrary
*/
private $data;

private $transparencyEnabled = false;

/**
* @param string $path
* @return void
Expand Down Expand Up @@ -323,6 +325,9 @@ public function enableTransparency()
{
imagealphablending($this->getImage(), false);
imagesavealpha($this->getImage(), true);

$this->transparencyEnabled = true;

return $this;
}

Expand All @@ -333,14 +338,33 @@ public function enableTransparency()
*/
public function fill()
{
$color = $this->getBackground();
$color = $this->getBackground();

if ($color === null) {
$color = "ffffff";
}

$background = null;

$background = imagecolorallocate(
if ($this->transparencyEnabled === true) {
$background = imagecolorallocatealpha(
$this->getImage(),
hexdec($color[0].$color[1]),
hexdec($color[2].$color[3]),
hexdec($color[4].$color[5])
);
hexdec($color[4].$color[5]),
127
);
}
else {

$background = imagecolorallocate(
$this->getImage(),
hexdec($color[0].$color[1]),
hexdec($color[2].$color[3]),
hexdec($color[4].$color[5])
);

}

imagefilledrectangle($this->getImage(), 0, 0, $this->getWidth(), $this->getHeight(), $background);

Expand Down Expand Up @@ -410,9 +434,13 @@ private function cropImage($leftOffset, $topOffset)
$class = __CLASS__;
$cropped = new $class();

$cropped->setWidth($this->getCropWidth())
->setHeight($this->getCropHeight())
->setBackground($this->getBackground());
$cropped->setMimeType($this->getMimeType()) // To enable again transparency on PNGs !
->setWidth($this->getCropWidth())
->setHeight($this->getCropHeight())
->setBackground($this->getBackground());


$cropped->background();

// Copy rendered image to cropped image
imagecopy(
Expand Down
10 changes: 8 additions & 2 deletions core/slir.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,9 @@ private function copySourceToRendered()
$this->getRendered()->background();

// Resample the original image into the resized canvas we set up earlier
if ($this->getSource()->getWidth() !== $this->getRendered()->getWidth() || $this->getSource()->getHeight() != $this->getRendered()->getHeight()) {
if ($this->getSource()->getWidth() !== $this->getRendered()->getWidth() ||
$this->getSource()->getHeight() != $this->getRendered()->getHeight()) {

$this->getSource()->resample($this->getRendered());
} else {
// No resizing is needed, so make a clean copy
Expand Down Expand Up @@ -699,7 +701,11 @@ private function makeIPTCTag($rec, $data, $value)
*/
private function isSourceImageDesired()
{
if ($this->isWidthDifferent() || $this->isHeightDifferent() || $this->isBackgroundFillOn() || $this->isQualityOn() || $this->isCroppingNeeded()) {
if ($this->isWidthDifferent() ||
$this->isHeightDifferent() ||
$this->isBackgroundFillOn() ||
$this->isQualityOn() ||
$this->isCroppingNeeded()) {
return false;
} else {
return true;
Expand Down

0 comments on commit 1fd8799

Please sign in to comment.