Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sharpen image quality with PHP gd library

Tags:

php

gd

not sure where but I came across as image hosting site that allows you to upload your image in a large format or to sharpen it.

I personally do not recall or know of any functions of GD library to sharpen image which might just be a different word for quality being up-ed.

If some one knows of a function to sharpen images please tell me since personally I am not aware of such functions neither in Image Magic and/or GD Library.

  • Thanks in advance
like image 478
PT Desu Avatar asked May 26 '11 16:05

PT Desu


1 Answers

You can use imageconvolution in GD with a sharpen mask. From http://adamhopkinson.co.uk/blog/2010/08/26/sharpen-an-image-using-php-and-gd/:

PHP and GD can sharpen images by providing a matrix to imageconvolution:

// create the image resource from a file
$i = imagecreatefromjpeg('otter.jpg');

// define the sharpen matrix
$sharpen = array(
  array(0.0, -1.0, 0.0),
  array(-1.0, 5.0, -1.0),
  array(0.0, -1.0, 0.0)
);

// calculate the sharpen divisor
$divisor = array_sum(array_map('array_sum', $sharpen));

// apply the matrix
imageconvolution($i, $sharpen, $divisor, 0);

// output the image
header('Content-Type: image/jpeg');
imagejpeg($i);
like image 90
brian_d Avatar answered Oct 12 '22 22:10

brian_d