Jump to content

Recommended Posts

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]
<?php

function 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

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.php
It'll tell you if PNG is supported or not. Just one other thing to eliminate.

[code=php:0]
<?php
if (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

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.