Jump to content

PHP image filtering


lenoir
 Share

Recommended Posts

Hi,

I want to process images being uploaded to PW by a client. Basically, making a sepia version of the images (with manual settings). I'm wondering: where's the best place/moment to implement this kind of process? Do you have any suggestions?

FYI: I'm also using the cropping image tool by Antti Peisa.

Here's my code. It loads the image, filters it and then overwrites it.

$image = imagecreatefromjpeg('myimage.jpg'); // the original file
imagefilter($image, IMG_FILTER_GRAYSCALE);
imagefilter($image, IMG_FILTER_COLORIZE, 19, 18, 0);
imagefilter($image, IMG_FILTER_BRIGHTNESS, -10);
imagefilter($image, IMG_FILTER_CONTRAST, -2);
imagejpeg($image, 'myimage.jpg'); // overwrites the original file.

Thanks!

Link to comment
Share on other sites

Greetings lenoir,

If you run it that way, you replace the image. That's fine, but you could also use a CSS filter to change it to sepia when the image is rendered.

There are still some cross-browser issues, but check here for info -> http://blog.teamtreehouse.com/css-filter-effects

There is also a nice JQuery method for doing this -> http://css.dzone.com/articles/html5-image-effects-sepia

With either of these methods, you could easily run it right inside your template.

Thanks,

Matthew

  • Like 2
Link to comment
Share on other sites

Hi Matthew,

Thanks for your reply. That's what i looked at in the first place, but with PHP i'm sure it'll be rendered correctly in all browsers, with or without js activated.

I think it'd be more efficient dropping these 4-5 lines of code upon saving or uploading the image…

David

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...