kernelgpf Posted October 21, 2007 Share Posted October 21, 2007 My problem is I'm getting an error saying my image is not a valid .png file the second time I tried to run the script.. I viewed the image, it still looks the same. I'm trying to replace the red in this image- http://www.dragon-dynasty.com/waterdragon.png with a hex code specified in this script. Help? Pre-thanks! <?php $v=$_SERVER['DOCUMENT_ROOT']; function change_color($image, $old_color, $new_color, $threshold = 15) { $image_width = imagesx($image); $image_height = imagesy($image); // iterate through x axis for ($x = 0; $x < $image_width; $x++) { // iterate through y axis for ($y = 0; $y < $image_height; $y++) { // look at current pixel $pixel_color = imagecolorat($image, $x, $y); if (($pixel_color <= $old_color + $threshold) && ($pixel_color >= $old_color - $threshold)) { // replace with new color imagesetpixel($image, $x, $y, $new_color); } } } } // EXAMPLE: // convert all red in the image to green $image = imagecreatefrompng("$v/waterdragon.png"); $red_rbg = 16646146; $green_rbg = 65341; change_color($image, $red_rbg, $green_rbg, 15); imagejpeg($image,"$v/waterdragon.png"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/ Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 Change $image = imagecreatefrompng("$v/waterdragon.png"); to your exact path (take out the $v) to the image.. and see if you stil get the error so put the image in the same directory as your script and just have this: $image = imagecreatefrompng("waterdragon.png"); See if thats the prob Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374467 Share on other sites More sharing options...
kernelgpf Posted October 21, 2007 Author Share Posted October 21, 2007 Warning: imagecreatefrompng() [function.imagecreatefrompng]: 'waterdragon.png' is not a valid PNG file in /home/.leucorhinos/kernelgpf/dragon-dynasty.com/test.php on line 28 Warning: imagesx(): supplied argument is not a valid Image resource in /home/.leucorhinos/kernelgpf/dragon-dynasty.com/test.php on line 5 Warning: imagesy(): supplied argument is not a valid Image resource in /home/.leucorhinos/kernelgpf/dragon-dynasty.com/test.php on line 6 Warning: imagepng(): supplied argument is not a valid Image resource in /home/.leucorhinos/kernelgpf/dragon-dynasty.com/test.php on line 32 Dun think so. =/ Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374479 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 Change imagejpeg($image,"$v/waterdragon.png"); to imagepng($image,"$v/waterdragon.png"); lol Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374482 Share on other sites More sharing options...
kernelgpf Posted October 21, 2007 Author Share Posted October 21, 2007 Same errors. Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374486 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 All i can figure is that it cant find the image... because im having trouble finding anymore errors Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374488 Share on other sites More sharing options...
kernelgpf Posted October 21, 2007 Author Share Posted October 21, 2007 Yeah.. I figured that. =/ How is it not a valid image? -Googles- Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374489 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 ^ open it in photoshop of something and re-save it.. then try it Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374491 Share on other sites More sharing options...
kernelgpf Posted October 21, 2007 Author Share Posted October 21, 2007 Okay.. I fixed that error. But now NOTHING is showing up on the screen.. ? You can see the results here: dragon-dynasty.com/test.php Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374494 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 re-post your new code Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374497 Share on other sites More sharing options...
kernelgpf Posted October 21, 2007 Author Share Posted October 21, 2007 <?php $v=$_SERVER['DOCUMENT_ROOT']; function change_color($image, $old_color, $new_color, $threshold = 15) { $image_width = imagesx($image); $image_height = imagesy($image); // iterate through x axis for ($x = 0; $x < $image_width; $x++) { // iterate through y axis for ($y = 0; $y < $image_height; $y++) { // look at current pixel $pixel_color = imagecolorat($image, $x, $y); if (($pixel_color <= $old_color + $threshold) && ($pixel_color >= $old_color - $threshold)) { // replace with new color imagesetpixel($image, $x, $y, $new_color); } } } } // EXAMPLE: // convert all red in the image to green $image = imagecreatefrompng("$v/waterdragon.png"); $red_rbg = 16646146; $green_rbg = 65341; change_color($image, $red_rbg, $green_rbg, 15); imagepng($image,"$v/waterdragon.png"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374498 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 [edit] scratch this post Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374500 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 try <?php $v=$_SERVER['DOCUMENT_ROOT']; function change_color($image, $old_color, $new_color, $threshold = 15) { $image_width = imagesx($image); $image_height = imagesy($image); // iterate through x axis for ($x = 0; $x < $image_width; $x++) { // iterate through y axis for ($y = 0; $y < $image_height; $y++) { // look at current pixel $pixel_color = imagecolorat($image, $x, $y); if (($pixel_color <= $old_color + $threshold) && ($pixel_color >= $old_color - $threshold)) { // replace with new color imagesetpixel($image, $x, $y, $new_color); } } } return $image; } // EXAMPLE: // convert all red in the image to green $image = imagecreatefrompng("$v/waterdragon.png"); $red_rbg = 16646146; $green_rbg = 65341; $image = change_color($image, $red_rbg, $green_rbg, 15); imagepng($image,"$v/waterdragon.png"); ?> lol.. im trying all i can think of.. just work with me Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374502 Share on other sites More sharing options...
kernelgpf Posted October 21, 2007 Author Share Posted October 21, 2007 Okay.. the first thing you posted.. the two things said exactly the same thing, and I tried the second thing, doesn't work. Thanks for your help though. ^^ Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374510 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 ^ Yeah.. the first thing was accident.. its late lol And the second thing.. bummer Im out of ideas dude Quote Link to comment https://forums.phpfreaks.com/topic/74150-dynamically-changing-color-of-photo/#findComment-374515 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.