/    Sign up×
Community /Pin to ProfileBookmark

edit colours of existing image- how?

I’m having a little trouble finding out how to edit the colours of an existing image and output it through php. For example, if I tell it to read an image in a folder but change X colour, how would that be done? The only ways I’ve discovered so far involve images made there and then, on-the-fly, not existing files.

Can anyone point me in the right direction?

Cheers.

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@PunkSktBrdr01Oct 16.2003 — I've never done anything like this, but if you are using a palette-based image, try [URL=http://us4.php.net/manual/en/function.imagecolorset.php]imagecolorset()[/URL].
Copy linkTweet thisAlerts:
@mityaauthorOct 16.2003 — THanks for that but I still don't know how to actually apply this to an existing image. How do you return the image and show its results afterwards?

I can't seem to crack this, despite extensive research.

Thanks
Copy linkTweet thisAlerts:
@PunkSktBrdr01Oct 16.2003 — Wouldn't returning the image show the results? Anyway, read the documentation for imagecolorset().
Copy linkTweet thisAlerts:
@mityaauthorOct 16.2003 — Nah returning it shows nothing, and if I try to display the image of <img src="<?php echo $im_object; ?>"> I get a failed image because it's looking for an image called 'resource locator #1.gif'.

When you first specify $im_object, do I simply say...

$image = "imgs/logo.gif";

or the whole caboodle, ala...

$file = "imgs/logo.gif";

$pointer = fopen($file, "r");

$image_to_feed_to_function = fread($pointer, filesize($file));

I'll have a *second* read of the bit you mentioned.

p.s. I've tried it with other image formats too.
Copy linkTweet thisAlerts:
@PunkSktBrdr01Oct 16.2003 — I'm kinda confused... Post the code.
Copy linkTweet thisAlerts:
@mityaauthorOct 17.2003 — Umm I can't really post anything other than what I did. Perhaps I should just re-word it better.

Basically, the above post by me was showing the different ways I've tried to OPEN an EXISTING image and then feed it to an image-treating function which changes colours.

You have to specify an object, right? Such as:

$image_object = imagecreatefrompng($image, etc...

But to feed it $image, do you open it with:

$image = "imgs/logo.gif";

...or the other way, i.e. using a $file, $handle and fread etc?

Hope this makes sense- thanks for perseverance.
Copy linkTweet thisAlerts:
@pyroOct 17.2003 — You're outputting the image wrong. Take a look at this. This will take the image foo.gif, change all the black to red, and output it as a png.

[code=php]<?php
header("Content-type: image/png");
$im = imagecreatefromgif("foo.gif");
imagecolorset ($im, 0, 255, 0, 0);
imagepng ($im);
imagedestroy ($im);
?>[/code]
Copy linkTweet thisAlerts:
@mityaauthorOct 17.2003 — Now I'm starting to really dislike you, Pyro, this is the umteenth time you've pissed all over my problems and effortlessly solved it!

Thanks mate.
Copy linkTweet thisAlerts:
@pyroOct 17.2003 — lol... ?

No problem, buddy...
×

Success!

Help @mitya spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...