|
Posted by Michel on 06/25/05 16:49
Hi Andy,
Great help this is indeed....
But... this creates a new image.
Is it possible to change the color of an existing image too?
Thanks,
MIchel
"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:c3mqb1prprq2451gbrahhk3tjv1tahacqh@4ax.com...
> On Fri, 24 Jun 2005 16:22:52 +0200, "Michel" <no@spam.please> wrote:
>
> >I wonder if what I have in mind is possible, maybe even not all that
> >complicated:
> >
> >I have an image, which is a yellow circle. I want this yellow circle to
> >change color by having 3 sliders (RGB) on a website and a button to
process
> >it.
> >
> >Is this at all possible and could someone point me in the right direction
or
> >a script that does this?
>
> Depends when you want the image to change. The PHP answer is that you
have to
> submit the form back to PHP each time you want the image to change, so PHP
can
> regenerate it and send it back.
>
> Another snag is that HTML forms don't include slider controls, so you'd
have
> to have something else like a series of radio buttons or an input box with
a
> number in it.
>
> circle.php :
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <html>
> <head>
> <title>circle</title>
> </head>
> <body>
> <?php
> $r = isset($_GET['r']) ? (int)$_GET['r'] : 255;
> $g = isset($_GET['g']) ? (int)$_GET['g'] : 255;
> $b = isset($_GET['b']) ? (int)$_GET['b'] : 0;
> print "<img src='image.php?r=$r&g=$g&b=$b' alt=''>";
> ?>
>
> <form method='get' action='circle.php'>
> R<input type='text' name='r' value='<?php print $r; ?>' size='3'>
> G<input type='text' name='g' value='<?php print $g; ?>' size='3'>
> B<input type='text' name='b' value='<?php print $b; ?>' size='3'>
> <input type='submit' value='process'>
> </form>
>
> </body>
> </html>
>
>
> image.php :
>
> <?php
> $im = imagecreate(96, 96);
> $white = imagecolorallocate($im, 255, 255, 255);
>
> $r = (int)$_GET['r'];
> $g = (int)$_GET['g'];
> $b = (int)$_GET['b'];
>
> $fill = imagecolorallocate($im, $r, $g, $b);
>
> imagefilledellipse($im, 48, 48, 96, 96, $fill);
>
> header('Content-type: image/png');
> imagepng($im);
> ?>
>
> Another approach could be Javascript based, changing the src attribute of
an
> <img> tag in response to user input to call a PHP script with parameters
> controlling the image colour.
>
> --
> Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
[Back to original message]
|