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.


Making a mask using the threshold function.

 
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
olfudydudy
Newbie


Joined: 12 Oct 2004
Posts: 10
Location: Atlanta, GA

PostPosted: Tue Feb 22, 2005 12:45 pm    Post subject: Making a mask using the threshold function. Reply with quote

Hi Andy,
Greetings from Atlanta. Thanks again for the overlay help.
I had another idea. Would it be possible to use the threshold function to make a black and white image and then make the white areas transparent? Then you could use it as a mask for the Image Mask class. How might you go about doing that, or is it possible using php? Was just wondering. Confused
Thanks,
George
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
amnuts
Site Admin


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

PostPosted: Wed Feb 23, 2005 4:01 am    Post subject: Reply with quote

Hi George,

It certainly should be possible, so long as you bare one thing in mind. The threshold method does just a pure black/white image with no greyscale. A colour is either above the threshold or below it. So long as you don't mind your mask being like that...

First thing to do is load up an image, send it to the threshold method, save it and then pass it into the image mask class. So off the top of my head (and bareing in mind that I've just got into work and hate mornings... Wink )

PHP:
<?php

require 'class.imagemask.php';
require 
'class.image.php';

$m =& new imageMask();

$m->loadImage('tobethemask.jpg');
Image::threshold($m->_img['orig'], 128);
$m->_img['final'] =& $m->_img['orig'];
$m->saveImage('mask.png');

$m->maskOption(mdCENTRE);
if (
$m->loadImage('imagetoapplymaskto.jpg')) {
    if (
$m->applyMask('mask.png')) {
        
$m->showImage('png');
    }
}

?>


Okay, technically the _img array should be a private variable and so not used in such a direct way as above. But this isn't PHP5, so we can be a little more flexible. Wink

Oh course, you could just directly use imagecreatefromjpeg() and such to create the mask-to-be image resource. I, however, opted to use the mask class.

Please remember that I haven't tried the above, so it may or may not work. But in theory it should be pretty sound. Smile

Let me know if that works out for you!

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


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

PostPosted: Wed Feb 23, 2005 4:03 am    Post subject: Reply with quote

Oh, as for making the white transparent, try looking into imagecolortransparent():

http://www.php.net/imagecolortransparent

That might help out.

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