Created
August 30, 2019 18:21
-
-
Save b2z/7920cb57a7576ad5c169298c9e659ff3 to your computer and use it in GitHub Desktop.
Sharpness function for GD to make images not so blurry after resize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function setSharpness($amount = 4) | |
{ | |
if ($amount < 0 || $amount > 100) | |
{ | |
$amount = 4; | |
} | |
$min = $amount >= 10 ? $amount * -0.01 : 0; | |
$max = $amount * -0.025; | |
$abs = ((4 * $min + 4 * $max) * -1) + 1; | |
$div = 1; | |
$matrix = [ | |
[$min, $max, $min], | |
[$max, $abs, $max], | |
[$min, $max, $min] | |
]; | |
imageconvolution($imageHandle, $matrix, $div, 0); | |
return $this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment