# [PATCH] Image sharpening function for ext/gd

- Thread: https://externals.io/message/5688
- Original archive: https://news-web.php.net/php.internals/5688
- Started by Paul Troughton on 2003-11-24T15:09:43+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #5688 — Paul Troughton — 2003-11-24T15:09:43+00:00

URL: https://externals.io/message/5688#5688

Hello,

I was surprised to find that, although the GD image-handling functions 
shipped with PHP do many useful things very well, there's no function 
to sharpen an image. I found a few posts bemoaning this absence, and 
therefore attach a patch which adds the function

   int imagesharpen ( resource im, int pct )

It performs the sharpening in-place. pct is the degree of sharpening to 
be applied: 0 does nothing; 100 gives a quite noticeable effect. Values 
 >100 can be used for stronger sharpening. Negative values are treated 
as 0.

The routine only sharpens truecolor images, as it rarely makes sense to 
attempt the operation on palletted images.

It's a simple linear sharpening routine using a 3x3 kernel, rather than 
the more flexible, but slower, unsharp masking approach used in e.g. 
Photoshop, Imagemagick. However it's very effective at making resampled 
photographic images (such as thumbnails) look a little more crisp.

I've built and tested it using gcc 3.3 under Mac OS X 10.3.1. There's 
nothing I'd expect to be platform-dependent in it. The attached patch 
is against php4-STABLE-200311202030, but it should work with most 
varieties of php-4.3.4, as the new code is fairly self-contained.

This is my first patch for PHP. Is there anything else I should do, 
beyond posting it here?

Many thanks,


Paul.

-- 
Paul Troughton         http://paul.troughton.org/
mobile +44 7866 041144       home +44 1223 366900

---

## #5691 — Jani Taskinen — 2003-11-24T15:40:49+00:00

URL: https://externals.io/message/5688#5691 · In reply to: #5688

There's new function in PHP 5 CVS, imagefilter(),
    I'd guess this would be good addition into that one..
    
    --Jani
    



>Hello,
>
>I was surprised to find that, although the GD image-handling functions 
>shipped with PHP do many useful things very well, there's no function 
>to sharpen an image. I found a few posts bemoaning this absence, and 
>therefore attach a patch which adds the function
>
>   int imagesharpen ( resource im, int pct )
>
>It performs the sharpening in-place. pct is the degree of sharpening to 
>be applied: 0 does nothing; 100 gives a quite noticeable effect. Values 
> > […]
>as 0.
>
>The routine only sharpens truecolor images, as it rarely makes sense to 
>attempt the operation on palletted images.
>
>It's a simple linear sharpening routine using a 3x3 kernel, rather than 
>the more flexible, but slower, unsharp masking approach used in e.g. 
>Photoshop, Imagemagick. However it's very effective at making resampled 
>photographic images (such as thumbnails) look a little more crisp.
>
>I've built and tested it using gcc 3.3 under Mac OS X 10.3.1. There's 
>nothing I'd expect to be platform-dependent in it. The attached patch 
>is against php4-STABLE-200311202030, but it should work with most 
>varieties of php-4.3.4, as the new code is fairly self-contained.
>
>This is my first patch for PHP. Is there anything else I should do, 
>beyond posting it here?
>
>Many thanks,
>
>
>Paul.

---

## #5697 — Paul Troughton — 2003-11-24T16:31:54+00:00

URL: https://externals.io/message/5688#5697 · In reply to: #5688

Second attempt at posting, this time hopefully with the patch as a MIME 
type that won't be stripped...



> Hello,
>
> I was surprised to find that, although the GD image-handling functions 
> shipped with PHP do many useful things very well, there's no function 
> to sharpen an image. I found a few posts bemoaning this absence, and 
> therefore attach a patch which adds the function
>
>   int imagesharpen ( resource im, int pct )
>
> It performs the sharpening in-place. pct is the degree of sharpening 
> to be applied: 0 does nothing; 100 gives a quite noticeable effect. 
> Values >100 can be used for stronger sharpening. Negative values are 
> treated as 0.
>
> The routine only sharpens truecolor images, as it rarely makes sense 
> to attempt the operation on palletted images.
>
> It's a simple linear sharpening routine using a 3x3 kernel, rather 
> than the more flexible, but slower, unsharp masking approach used in 
> e.g. Photoshop, Imagemagick. However it's very effective at making 
> resampled photographic images (such as thumbnails) look a little more 
> crisp.
>
> I've built and tested it using gcc 3.3 under Mac OS X 10.3.1. There's 
> nothing I'd expect to be platform-dependent in it. The attached patch 
> is against php4-STABLE-200311202030, but it should work with most 
> varieties of php-4.3.4, as the new code is fairly self-contained.
>
> This is my first patch for PHP. Is there anything else I should do, 
> beyond posting it here?
>
> Many thanks,
>
>
> Paul.
>
> -- 
> Paul Troughton         http://paul.troughton.org/
> mobile +44 7866 041144       home +44 1223 366900
