Skip to content

Commit

Permalink
Update az.multi.upload.class.php
Browse files Browse the repository at this point in the history
refine compress function.
  • Loading branch information
mianzaid authored Aug 19, 2020
1 parent 0611470 commit 0cd71df
Showing 1 changed file with 19 additions and 38 deletions.
57 changes: 19 additions & 38 deletions az.multi.upload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,62 +31,43 @@ public function compressImage($sourceURL, $destinationURL, $minImgWidth, $wmImag
$newHeight = $height;
}

$watermark = imagecreatefrompng($wmImageSource);

$imgResource = imagecreatetruecolor($newWidth, $newHeight);
$image = '';
if ($infoImg['mime'] == 'image/jpeg') {
$image = imagecreatefromjpeg($sourceURL);
// Set the margins for the watermark and get the height/width of the watermark image
$positionRight = $positionX;
$positionBottom = $positionY;
$sx = imagesx($watermark);
$sy = imagesy($watermark);
// width to calculate positioning of the watermark.
imagecopy($image, $watermark, imagesx($image) - $sx - $positionRight, imagesy($image) - $sy - $positionBottom, 0, 0, imagesx($watermark), imagesy($watermark));

imagecopyresampled($imgResource, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
} elseif ($infoImg['mime'] == 'image/jpg') {
$image = imagecreatefromjpeg($sourceURL);
// Set the margins for the watermark and get the height/width of the watermark image
$positionRight = $positionX;
$positionBottom = $positionY;
$sx = imagesx($watermark);
$sy = imagesy($watermark);
// width to calculate positioning of the watermark.
imagecopy($image, $watermark, imagesx($image) - $sx - $positionRight, imagesy($image) - $sy - $positionBottom, 0, 0, imagesx($watermark), imagesy($watermark));

imagecopyresampled($imgResource, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
} elseif ($infoImg['mime'] == 'image/png') {
$image = imagecreatefrompng($sourceURL);
// Set the margins for the watermark and get the height/width of the watermark image
$positionRight = $positionX;
$positionBottom = $positionY;
$sx = imagesx($watermark);
$sy = imagesy($watermark);
// width to calculate positioning of the watermark.
imagecopy($image, $watermark, imagesx($image) - $sx - $positionRight, imagesy($image) - $sy - $positionBottom, 0, 0, imagesx($watermark), imagesy($watermark));

imagealphablending($image, false);
imagesavealpha($image, true);

imagecopyresampled($imgResource, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
} elseif ($infoImg['mime'] == 'image/gif') {
$image = imagecreatefromgif($sourceURL);
}


$imgResource = imagecreatetruecolor($newWidth, $newHeight);

if (!empty($wmImageSource)) {
$watermark = imagecreatefrompng($wmImageSource);
// Set the margins for the watermark and get the height/width of the watermark image
$positionRight = $positionX;
$positionBottom = $positionY;
$sx = imagesx($watermark);
$sy = imagesy($watermark);
// width to calculate positioning of the watermark.
imagecopy($image, $watermark, imagesx($image) - $sx - $positionRight, imagesy($image) - $sy - $positionBottom, 0, 0, imagesx($watermark), imagesy($watermark));
}
imagealphablending($imgResource, false);
imagesavealpha($imgResource, true);

imagealphablending($image, false);
imagesavealpha($image, true);
imagecopyresampled($imgResource, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
if ($infoImg['mime'] == 'image/png' || $infoImg['mime'] == 'image/gif') {

imagecopyresampled($imgResource, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
$newQuality = ($quality / 10) - 1;
imagealphablending($imgResource, false);
imagesavealpha($imgResource, true);
$RET = imagepng($imgResource, $destinationURL, $newQuality); //For png quality range is 0-9
} else {
$RET = imagejpeg($imgResource, $destinationURL, $quality);
}

$RET = imagejpeg($imgResource, $destinationURL, $quality);
imagedestroy($image);
return $RET;
}
Expand Down

0 comments on commit 0cd71df

Please sign in to comment.