What's wrong with this code?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jellybellys
Forum Newbie
Posts: 1
Joined: Mon Jul 25, 2011 1:24 pm

What's wrong with this code?

Post 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:
Image
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: What's wrong with this code?

Post by Benjamin »

Have you checked for errors/warnings/notices? What are they?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: What's wrong with this code?

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
SabirAhmed
Forum Newbie
Posts: 23
Joined: Tue Aug 02, 2011 11:56 am

Re: What's wrong with this code?

Post 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
genix2011
Forum Commoner
Posts: 74
Joined: Tue Aug 02, 2011 4:00 pm

Re: What's wrong with this code?

Post 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 '!='.
SabirAhmed
Forum Newbie
Posts: 23
Joined: Tue Aug 02, 2011 11:56 am

Re: What's wrong with this code?

Post by SabirAhmed »

so i was right? yippee , thats kudos for a newb like me :)
Post Reply