HAMM3R Posted August 10, 2006 Share Posted August 10, 2006 Hey. I got this script from http://www.phparadise.de/php-code/image-editing/invert-image/It works with jpegs but I cant get it to work with PNGs. Everytime i try it i see a "The image “http://domain.com/graphs.php” cannot be displayed, because it contains errors." in firefox and IE just tells me action canceled. Im sure ive just got something wrong in the code. Can someone please tell me what ive done wrong? Here is what im using:[code]<?phpfunction invert_image($input,$output,$color=false,$type='jpeg'){ if($type == 'jpeg') $bild = imagecreatefromjpeg($input); else $bild = imagecreatefrompng($input); $x = imagesx($bild); $y = imagesy($bild); for($i=0; $i<$y; $i++) { for($j=0; $j<$x; $j++) { $pos = imagecolorat($bild, $j, $i); $f = imagecolorsforindex($bild, $pos); if($color == true) { $col = imagecolorresolve($bild, 255-$f['red'], 255-$f['green'], 255-$f['blue']); }else{ $gst = $f['red']*0.15 + $f['green']*0.5 + $f['blue']*0.35; $col = imagecolorclosesthwb($bild, 255-$gst, 255-$gst, 255-$gst); } imagesetpixel($bild, $j, $i, $col); } } if(empty($output)) header('Content-type: image/'.$type); if($type == 'jpeg') imagejpeg($bild,$output,90); else imagepng($bild,$output);}$input = 'http://www.game-monitor.com/server-players.php?ip=70.86.246.26:7777&type=day&key=f9f8b008dfd594f80f8f81468f5836e5&timezone=-4.png';// for a color negative image, set the optional flag// invert_image($input,'',true,'png');// for a black and withe negative image use like this//// invert_image($input,'');// if you want to save the output instead of just showing it,// set the output to the path where you want to save the inverted image//// invert_image('path/to/original/image.jpg','path/to/save/inverted-image.jpg');// if you want to use png you have to set the color flag as// true or false and define the imagetype in the function call//invert_image($input,'',true,'png');?>[/code]Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/17101-invert-image-colors/ Share on other sites More sharing options...
xAtlas Posted August 10, 2006 Share Posted August 10, 2006 Have you tried changing the jpeg to png in:function invert_image($input,$output,$color=false,$type='jpeg')? Link to comment https://forums.phpfreaks.com/topic/17101-invert-image-colors/#findComment-72623 Share on other sites More sharing options...
HAMM3R Posted August 10, 2006 Author Share Posted August 10, 2006 Yes i tired that and it made no difference :( Link to comment https://forums.phpfreaks.com/topic/17101-invert-image-colors/#findComment-72675 Share on other sites More sharing options...
xAtlas Posted August 11, 2006 Share Posted August 11, 2006 Is PNG supported? Most times they are I suppose but you can copy the below, save it as PNG.PHP and upload it to your website then run it: yoursite.com/png.phpIt'll tell you if PNG is supported or not. Just one other thing to eliminate.[code=php:0]<?phpif (imagetypes() & IMG_PNG) { echo "PNG Support is enabled";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/17101-invert-image-colors/#findComment-73035 Share on other sites More sharing options...
xAtlas Posted August 11, 2006 Share Posted August 11, 2006 Hmm.. give this a try:replace[code]else $bild = imagecreatefrompng($input);[/code]to[code]elseif($type =='png') $bild = imagecreatefrompng($input);[/code] Link to comment https://forums.phpfreaks.com/topic/17101-invert-image-colors/#findComment-73048 Share on other sites More sharing options...
HAMM3R Posted August 13, 2006 Author Share Posted August 13, 2006 Yeah it says PNG support is enabled and i changed that line. It made no difference :(Maybe i can convert the png to jpg since i know the jpg invert works? How do I do that? Link to comment https://forums.phpfreaks.com/topic/17101-invert-image-colors/#findComment-73928 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.