Page 1 of 1
What's wrong with this code?
Posted: Mon Jul 25, 2011 1:27 pm
by jellybellys
Code: Select all
<?php
$intype = $_GET['intype'];
$outtype = $_GET['outtype'];
if ($_GET['type'] <> ''){
$intype = $_GET['type'];
$outtype = $_GET['type'];
}
$alpha = $_GET['alpha'];
$url = $_GET['url'];
$watermark = $_GET['watermark'];
if ($intype = 'png'){
$img = imagecreatefrompng($url);
if ($alpha = 'true'){
imagealphablending($img, true);
imagesavealpha($img, true);
}
}
if ($intype = 'jpeg' || $intype = 'jpg'){
$img = imagecreatefromjpeg($url);
}
if ($intype = 'gif'){
$img = imagecreatefromgif($url);
}
if ($watermark <> 'false'){
$textcolor = imagecolorallocate($img, 0, 0, 255);
imagestring($img, 3, 0, 0, 'cprox.org', $textcolor);
}
if ($outtype = 'png'){
header('Content-Type: image/png');
imagepng($img);
}
if ($outtype = 'jpeg' || $outtype = 'jpg'){
header('Content-Type: image/jpeg');
imagejpeg($img);
}
if ($outtype = 'gif'){
header('Content-Type: image/gif');
imagegif($img);
}
imagedestroy($img);
?>
All I get is:

Re: What's wrong with this code?
Posted: Tue Jul 26, 2011 3:53 am
by Benjamin
Have you checked for errors/warnings/notices? What are they?
Re: What's wrong with this code?
Posted: Tue Jul 26, 2011 3:09 pm
by pickle
Either the page from which you're calling this file isn't referencing it properly, which means the browser can't find it, or the image data returned by this file is broken/incomplete.
Re: What's wrong with this code?
Posted: Tue Aug 02, 2011 7:44 pm
by SabirAhmed
One possible suggestion, I found this worked for myself the other day, is to put a double-equals sign on the IF statements when trying to determine the file type :
if ($intype == 'gif')
{
}
Just on first glance it seems that may work, or it may not fit in with the rest of ur syntax, im not sure
Re: What's wrong with this code?
Posted: Tue Aug 02, 2011 8:24 pm
by genix2011
if($intype = 'gif') will always return true, because a single '=' assigns a value to a variable. To compare values you have to use the '==' operator.
I also wouldn't use '<>' but instead '!='.
Re: What's wrong with this code?
Posted: Tue Aug 02, 2011 9:33 pm
by SabirAhmed
so i was right? yippee , thats kudos for a newb like me
