Jump to content

Color Class implementation...


beta3designs

Recommended Posts

First... hello everyone! I'm new to these forums, not to PHP (anyway I consider myself a beginner so don't be too harsh with me please  :P) and I hope to get some help and to help as much as I can :)

Well, let's get down to business  ::)

I'm making a Color class with conversions between different colorspaces, colors, etc. so it can be helpful later to use with image libraries, like GD or ImageMagick...

So I've come to a point where I don't know what to do. A lot of ways of implementing this class come to my head and I don't know which one would be the best to keep working on (I mean, it isn't finished and I don't want to write both, I'd like to choose one). So that's basically what I want you to help me with... to choose one of these two. The one you think would be better in every aspect especially when processing images.

Also if you find any errors, or have any ideas, anything... please let me know i will really appreciate it  :D

Attached are the two implementations.

Below I post some basic examples of how to use each one but I think it's easy enough.

 

color.class.php:

<?php
require_once("color.class.php");

print Color::rgb2hex(array(255,0,255),0,1);
print "<br/>";

$col = new Color;
$col->set_from_hex("#FF0000");

$col2 = new Color;
$col2->set_from_cmy(0, 1, 1);

print $col2->get_hex(1, 1);
print "<br/>";
?>

 

color.class2.php:

<?php
require_once("color.class2.php");
$rgb1 = new rgbColor(255,0,0,255);
$rgb2 = new rgbColor(255,0,0,255);
$cmy = new cmyColor(0,1,1,1);
$cmyk = new cmykColor(0,1,1,0,1);

print $rgb1->equals($rgb2);
print "<br/>";

print $cmyk;
print "<br/>";

print ColorConverter::toCmyk($rgb1);
print "<br/>";

print $rgb1->getAlpha();
?>

 

Thanks in advance!

 

P.S: In case you aren't familiar with colorspaces... RGB components are in the range 0..255, CMY and CMYK in the range 0..1, and notice the second implementation has also alpha channel while the first one doesn't (just cause when I wrote it I didn't think about it... :P)

 

[attachment deleted by admin]

Link to comment
Share on other sites

hello again! sorry for double posting but... it's been a week since i posted this, and i really need some advise, i know you just can take all the time to answer everyone in this forum but i really need some advise so i can continue with my project is all i ask for...

Thanks again!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.