andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Is there a way to tweak the Sepia Tone?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Image Functions
View previous topic :: View next topic  
Author Message
sloppyboy
Newbie


Joined: 23 Oct 2005
Posts: 3

PostPosted: Sun Oct 23, 2005 12:21 pm    Post subject: Is there a way to tweak the Sepia Tone? Reply with quote

Hello and thanks for developing these useful functions!

The sepia() function outputs an image that looks more pink than Sepia Tone. Is there a way to tweak this function so I can get the Sepia look that I'm looking for? How can I do this? Thanks!

Tom
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Oct 24, 2005 5:49 am    Post subject: Reply with quote

Hi, and welcome to the board!

All you'll need to do is tweak the hue and saturation values in the sepia function. Find these two lines:

Code:
$pxhls[0] = 0.30;
$pxhls[2] = 0.25;


And tweak the values. The first is the hue and the second the saturation. If you find that you want to tweak the lightness, then use $pxhls[1] and assign the value. The ranges for each of those is 0 to 1.

HTH

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
sloppyboy
Newbie


Joined: 23 Oct 2005
Posts: 3

PostPosted: Thu Oct 27, 2005 5:03 pm    Post subject: Anyone have a better Sepia function? Reply with quote

Hi Andy,

Thanks for replyling so quickly. I played with the hue and saturation numbers like you said but no matter what I change the numbers to the image appears to have a slight pink cast to it. I'm trying to go for more of a brown and white than pink and white. Are there other functions that I can use to achieve this?

I took one of my photos and converted it to sepia tone in photoshop.

Here is the original:


And here is the sepia version that I created in photoshop:


Can somebody help me write a function to get the original to look like the sepia that I created in photoshop? I would certainly appreciate it. Thanks!!!

Tom
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Fri Oct 28, 2005 8:58 am    Post subject: Reply with quote

Hi,

Doing this doesn't produce a bad result:

PHP:
<?php

    
require_once('class.image.php');
    
set_time_limit(720);
    
$img imagecreatefromjpeg('color.jpg');

    
Image::greyscale($img);
    
Image::colourise($img'A09182');

    
header('Content-type: image/jpeg');
    
imagejpeg($img);

?>


This gives quite a nice tone, too:

Image::colourise($img, 'B39C86');

Just try playing aorund with it, passing a sepia tone that you like. Try it without setting to greyscale, too, as it might produce simialr result and be a bit faster.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
sloppyboy
Newbie


Joined: 23 Oct 2005
Posts: 3

PostPosted: Sun Nov 06, 2005 4:47 pm    Post subject: THANK YOU!!! Reply with quote

THANKS ANDY!!!! This works perfectly! Very Happy Very Happy Very Happy

I went with using Image::colourise($img, 'A09182'); and skipped the greyscale conversion step.

Thanks again!

Tom
Back to top
View user's profile Send private message
aroth
Newbie


Joined: 26 Jan 2006
Posts: 1

PostPosted: Thu Jan 26, 2006 1:54 pm    Post subject: Sepia using colorize is too slow Reply with quote

Hi Andy

Thanks for the code sample -- it was pretty much what my client was using. The problem, however, is speed. It's the best sepia producing code we've found, but its terribly slow. Is there anyway around this? We've got to solve this problem ASAP.

1/26/06

Thanks
Adam
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Fri Jan 27, 2006 3:51 am    Post subject: Reply with quote

Hi Adam - welcome to the board!

Unfortunately there's no real way to speed up the PHP code as it is. The sepia tone is made by going over the image one pixel at a time, adjusting the colour and writing it back to the image, and all of that is done by an interpreted language. If you want real performance then your best bet would probably be a compiled library such as ImageMagick. You can find PHP extensions for ImageMagick, or pass it commands via the shell.

Alternatively, if you want to stick with PHP/GD then you could try using the imagecopymerge function. Load your image into an image resource, create another image resource of the same size and fill it with your tone colour, then merge the colour on top of the image with whatever percentage your want. Results wont be as good, but it would be a hell of a lot faster.

Regards,

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Image Functions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group