Skip to content

Instantly share code, notes, and snippets.

@b2z
Created August 30, 2019 18:21
Show Gist options
  • Save b2z/7920cb57a7576ad5c169298c9e659ff3 to your computer and use it in GitHub Desktop.
Save b2z/7920cb57a7576ad5c169298c9e659ff3 to your computer and use it in GitHub Desktop.
Sharpness function for GD to make images not so blurry after resize
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