Jump to content

Imagecreate error.


maxxn

Recommended Posts

Does anyone know what's wrong with this, it keeps returning Your image format is not supported. Please use a PNG, GIF, or JPEG. This happens even when I do use jpeg, gif or png.

 

// image

if ($text == "jpg") {

  $text = "jpeg";

}

 

$gdcall = "imagecreatefrom".$text;

 

if (function_exists($gdcall)) {

  if (!($im = $gdcall($tname))) {

   echo "Error in image data.";

   $do = false;

  } else {

 

   $imgsize = getimagesize($tname);

   $iwidth=$imgsize['0'];

   $iheight=$imgsize['1'];

 

   $twidth = get_game_config("name=twidth");

   $theight = get_game_config("name=theight");

 

   $newim = imagecreatetruecolor($twidth, $theight);

 

   imagecopyresized(

   $newim,

   $im,

   0,

   0,

   0,

   0,

   $twidth,

   $theight,

   $iwidth,

   $iheight);

 

   if (!imagepng($newim, $cfg['instdir']."img/".$nameid.".png")) {

    echo "Error writing image.";

    $do = false;

   }

 

 

  }

 

} else {

  echo 'Your image format is not supported. Please use a PNG, GIF, or JPEG.';

  $do = false;

}

//////////////////

 

Thanks, any help would be appreciated!

Link to comment
https://forums.phpfreaks.com/topic/39835-imagecreate-error/
Share on other sites

Here's the whole php file incase anyone needs it.

 

<?php

$gameconfig = get_game_config();

function get_games($args='', $diffquery='') {

global $db, $gameconfig;

$args = parse_args($args);

isset($args['order']) ? $order=$args['order'] : $order = 'time';
isset($args['sort']) ? $sort=$args['sort'] : $sort = 'DESC';
isset($args['thecat']) ? $thecat=$args['thecat'] : $thecat = 'all';
isset($args['theauthor']) ? $theauthor=$args['theauthor'] : $theauthor = 'all';
isset($args['htmlize']) ? $htmlize=$args['htmlize'] : $htmlize = true;
isset($args['limitstart']) ? $limitstart=$args['limitstart'] : $limitstart = '';
isset($args['limitnum']) ? $limitnum=$args['limitnum'] : $limitnum = '';
isset($args['page']) ? $page=$args['page'] : $page = '-all-';
isset($args['shortdesc']) ? $shortdesc=$args['shortdesc'] : $shortdesc = '-';
isset($args['diffquery']) ? $diffquery=$args['diffquery'] : $diffquery = '';
isset($args['active']) ? $active=$args['active'] : $active = 'Yes';
isset($args['flags']) ? $flags=$args['flags'] : $flags = '-';

$order = mysql_escape_string($order);
$category = mysql_escape_string($thecat);

if ($order=="deforder") {
	$order = $gameconfig['order'];
}

if ($sort=="defsort") {
	$sort = $gameconfig['sort'];
}

if ($sort == 'DESC') {
	$sort = 'DESC';
} else {
	$sort = 'ASC';
}



$games = array();

if ($page != '-all-') {
	if (!is_numeric($page)) {
		$page = 1;
	}

	$gamesperpage = $gameconfig['gamesperpage'];
	$limitstart = ($page-1) * $gamesperpage;
	$limitnum = $gamesperpage;

}

if ($limitstart !== '' && $limitnum !== '') {
	$limit = "LIMIT $limitstart, $limitnum";
} else {
	$limit = "";
}

if ($active == '-all-') {
	$where = '';
} else {
	$where = "AND `active`='".$active."'";
}

if ($theauthor != 'all') {
	$where .= " AND `authorname`='".$theauthor."'";
}

if ($flags != '-') {
	$where .= " AND `flags` LIKE '%".$flags."%'";
}

if ($category == 'all') {
	$query = "SELECT * FROM games WHERE 1=1 ".$where." ORDER BY `".$order."` ".$sort.' '.$limit;
} else {
	$query = "SELECT * FROM games WHERE `cat` = '".$category."' ".$where." ORDER BY `".$order."` ".$sort.' '.$limit;
}

if ($diffquery != '') {
	$query = $diffquery;
}

$result = $db->query($query);

while (($game = mysql_fetch_array($result))) {
	if ($htmlize == true) {
		$game = array_map("myhtmlentities", $game);
	}

	if (is_numeric($shortdesc)) {
		if (strlen($game['desc']) > $shortdesc) {
			$game['fulldesc'] = $game['desc'];
			$game['desc'] = substr($game['desc'], 0, $shortdesc)."...";
		}
	}

	if ($gameconfig['deschtml']==1) {
		$game['desc'] = html_entity_decode($game['desc'], ENT_QUOTES);
	}

	$games[] = $game;
}



return $games;

}

function get_game($args='') {

global $db, $gameconfig;

$args = parse_args($args);

isset($args['htmlize']) ? $htmlize=$args['htmlize'] : $htmlize = true;
isset($args['id']) ? $id=$args['id'] : $id = mysql_escape_string($_REQUEST["id"]);
isset($args['maxwidth']) ? $maxwidth=$args['maxwidth'] : $maxwidth = -1;
isset($args['minwidth']) ? $minwidth=$args['minwidth'] : $minwidth = -1;

if ($id == '') {
	return false;
}

$result = $db->query("SELECT * FROM games WHERE `id`='".$id."' LIMIT 1");
$game = mysql_fetch_array($result);

if (mysql_num_rows($result) != 1) {
	return false;
}

if ($htmlize == true) {
	$game = array_map("myhtmlentities", $game);
}

// Set up the maximum and minimum width.
if ($game['type'] != 'CustomCode') {
	if ($maxwidth != -1 && $game['width'] > $maxwidth) {
		$prop = $maxwidth/$game['width'];
		$game['width'] = floor($maxwidth);
		$game['height'] = floor($prop*$game['height']);
	}
}

if ($minwidth != -1 && $game['width'] < $minwidth && $game['width']!=0) {
	$prop = $minwidth/$game['width'];
	$game['width'] = floor($minwidth);
	$game['height'] = floor($prop*$game['height']);
}

if ($game['type']=='SWF') {

	$game['code']  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'.$game['width'].'" height="'.$game['height'].'">';
	$game['code'] .= '<param name="movie" value="[swfdir]'.$game['nameid'].'.swf">';
	$game['code'] .= '<param name="quality" value="high">';
	$game['code'] .= '<param name="menu" value="true">';
	$game['code'] .= '<embed width="'.$game['width'].'" height="'.$game['height'].'" src="[swfdir]'.$game['nameid'].'.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash">';
	$game['code'] .= '</embed>';
	$game['code'] .= '</object>';

	$game['filename'] = $game['nameid'].".swf";

} else if ($game['type'] == 'DCR') {

	$game['code']  = '<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,0,0" width="'.$game['width'].'" height="'.$game['height'].'">';
	$game['code'] .= "<param name=swRemote value=\"swSaveEnabled='true' swVolume='true' swRestart='true' swPausePlay='true' swFastForward='true'   swContextMenu='true' \">";
	$game['code'] .= "<param name='swStretchStyle' value='fill'>";
	$game['code'] .= "<param name='bgColor' value='#000000'>";
	$game['code'] .= "<param name='src' value='[swfdir]".$game['nameid'].".dcr'>";
	$game['code'] .= "<embed src='[swfdir]".$game['nameid'].".dcr' bgcolor='#000000' width='".$game['width']."' height='".$game['height']."' swRemote=\"swSaveEnabled='true' swVolume='true' swRestart='true' swPausePlay='true' swFastForward='true' swContextMenu='true'\" swStretchStyle='fill' type='application/x-director' pluginspage='http://www.macromedia.com/shockwave/download/'></embed>";
	$game['code'] .= "</object>";

	$game['filename'] = $game['nameid'].".dcr";

} else if ($game['type'] == 'CustomCode') {
	$game['code'] = html_entity_decode($game['code'], ENT_QUOTES);
	$game['filename'] = "";
}

if ($gameconfig['deschtml']==1) {
	$game['desc'] = html_entity_decode($game['desc'], ENT_QUOTES);
}

$game['filename'] = $cfg['instdir']."swf/".$game['filename'];

return $game;
}

function get_recent_plays($args='', $diffquery='') {

global $db, $gameconfig;

$args = parse_args($args);

isset($args['order']) ? $order=$args['order'] : $order = 'time';
isset($args['sort']) ? $sort=$args['sort'] : $sort = 'DESC';
isset($args['limitstart']) ? $limitstart=$args['limitstart'] : $limitstart = '';
isset($args['limitnum']) ? $limitnum=$args['limitnum'] : $limitnum = '';
isset($args['diffquery']) ? $diffquery=$args['diffquery'] : $diffquery = '';

$order = mysql_escape_string($order);

if ($sort == 'DESC') {
	$sort = 'DESC';
} else {
	$sort = 'ASC';
}

if ($limitstart !== '' && $limitnum !== '') {
	$limit = "LIMIT $limitstart, $limitnum";
} else {
	$limit = "";
}

$query = "SELECT * FROM gameplays ORDER BY `".$order."` ".$sort.' '.$limit;

if ($diffquery != '') {
	$query = $diffquery;
}

$result = $db->query($query);

while (($play = mysql_fetch_array($result))) {
	$plays[] = $play;
}


return $plays;

}

function get_game_config($args='') {

global $db, $cfg;

$args = parse_args($args);

isset($args['name']) ? $name=$args['name'] : $name = '-getall-';

$name = mysql_escape_string($name);

$result = $db->query("SELECT * FROM games_config");

while (($line = mysql_fetch_array($result))) {
	$tname = $line['name'];

	if ($line['string']!='') {
		$value = $line['string'];
	} else {
		$value = $line['integer'];
	}

	$config[$tname]=$value;
}

if ($name == '-getall-') {
	return $config;
} else {
	return $config[$name];
}

}

function get_game_pages($args='') {

global $db;

$args = parse_args($args);

isset($args['thecat']) ? $thecat=$args['thecat'] : $thecat = 'all';
isset($args['theauthor']) ? $theauthor=$args['theauthor'] : $theauthor = 'all';

$category = mysql_escape_string($thecat);

if ($category == 'all') {
	$query = "SELECT * FROM games";
} else {
	$query = "SELECT * FROM games WHERE `cat` = '".$category."'";
}

if ($theauthor != 'all') {
	$query = "SELECT * FROM games WHERE `authorname` = '".$theauthor."'";
}

if ($diffquery != '') {
	$query = $diffquery;
}

$result = $db->query($query);
$numrows = mysql_num_rows($result);

$gamesperpage = get_game_config("name=gamesperpage");
$pagenum = $numrows / $gamesperpage;
$pagenum = ceil($pagenum);

return $pagenum;

}

function game_count_play() {

global $params, $db;

$id = mysql_escape_string($params[1]);

if ($_COOKIE["gamecookie"]!=$id) {

	setcookie("gamecookie", $params[1], time()+3600, "/");

	if (is_numeric($id)) {
		// Update plays for the game.
		$db->query("UPDATE games
		SET playcount=playcount+1
		WHERE id='".$id."'");
		$db->query("UPDATE games
		SET weeklyplays=weeklyplays+1
		WHERE id='".$id."'");

		// Update the daily play count and the total play count.
		$db->query("UPDATE `info`
		SET `integer`=`integer`+1
		WHERE `name`='dayplays'");
		$db->query("UPDATE `info`
		SET `integer`=`integer`+1
		WHERE `name`='totalplays'");

		// Update the latest plays.
		$db->query("
		INSERT INTO `gameplays` ( `id` , `gid` , `uid` , `time` )
		VALUES (
			'', '".$id."', '1', '".time()."'
		)
		");

	}

}


}

// Using this a lot is about as smart as playing football on skis.
// TODO: FIX IT
function get_total_game_plays() {
$games = get_games();

$plays = 0;
foreach ($games as $game) {
	$plays+=$game['playcount'];
}

return $plays;
}

function build_swf_select($args='') {

global $cfg;

$args = parse_args($args);
isset($args['name']) ? $name=$args['name'] : $name = 'swffileselect';

$select = "<select name='".$name."'>";

$dh = opendir($cfg['instdir']."uploadfiles");

while (($filename = readdir($dh)) !== false) {
	$files[] = $filename;
}
sort($files);


$arr = array();
foreach ($files as $file) {
	if ($file=='.' || $file=='..') continue;
	if ($file[0]!="~") {

		$pinfo = pathinfo($file);

		$extension = $pinfo['extension'];

		if ($extension == 'swf' || $extension == 'dcr') {
			$arr[] = $file;
		}

	}
}

$select .= "<option value=''>-</option>";

foreach ($arr as $file) {
	$select .= "<option value='".$file."'>".$file."</option>";
}

$select .= "</select>";

return $select;

}

function build_img_select($args='') {

global $cfg;

$args = parse_args($args);
isset($args['name']) ? $name=$args['name'] : $name = 'imgfileselect';

$select = "<select name='".$name."'>";

$dh = opendir($cfg['instdir']."uploadfiles");

while (($filename = readdir($dh)) !== false) {
	$files[] = $filename;
}
sort($files);


$arr = array();
foreach ($files as $file) {
	if ($file=='.' || $file=='..') continue;
	if ($file[0]!="~") {

		$pinfo = pathinfo($file);

		$extension = $pinfo['extension'];

		if ($extension == 'png' || $extension == 'jpg' || $extension == 'gif') {
			$arr[] = $file;
		}

	}
}

$select .= "<option value=''>-</option>";
foreach ($arr as $file) {
	$select .= "<option value='".$file."'>".$file."</option>";
}

$select .= "</select>";

return $select;

}

function dispgamecode_enabled() {

global $gameconfig;

if ($gameconfig['dispgamecode']==1) {
	return true;
} else {
	return false;
}

return false;
}

function get_categories($args='') {

global $db;

$args = parse_args($args);

isset($args['order']) ? $order=$args['order'] : $order = 'order';
isset($args['sort']) ? $sort=$args['sort'] : $sort = 'ASC';
isset($args['htmlize']) ? $htmlize=$args['htmlize'] : $htmlize = true;

$order = mysql_escape_string($order);

if ($sort == 'DESC') {
	$sort = 'DESC';
} else {
	$sort = 'ASC';
}

$categories = array();

$query = "SELECT * FROM categories ORDER BY `".$order."` ".$sort;
$result = $db->query($query);

while (($category = mysql_fetch_array($result))) {
	if ($htmlize == true) {
		$category = array_map("myhtmlentities", $category);
	}
	$categories[] = $category;
}

return $categories;

}

function get_category($args='') {

global $db;

$args = parse_args($args);

isset($args['id']) ? $id = $args['id'] : $id = $_REQUEST["id"];
isset($args['name']) ? $name = $args['name'] : $name = '';
isset($args['htmlize']) ? $htmlize=$args['htmlize'] : $htmlize = true;

$id = mysql_escape_string($id);

if ($name != '') {
	$result = $db->query("SELECT * FROM categories WHERE name='".$name."'");
} else {
	$result = $db->query("SELECT * FROM categories WHERE id='".$id."'");
}

$category = mysql_fetch_array($result);

if ($category==false) {
	return false;
}

if ($htmlize == true) {
	$category = array_map("myhtmlentities", $category);
}

return $category;

}

function build_category_select($args='') {

$args = parse_args($args);

isset($args['name']) ? $name=$args['name'] : $name = 'cat';
isset($args['prev']) ? $prev=$args['prev'] : $prev = '-nocat-';
isset($args['prevlang']) ? $prevlang = $args['prevlang'] : $prevlang='No Change';

$categories = get_categories("htmlize=true");

$select = "<select name='".$name."'>";

if ($prev != '-nocat-') {
	$select .= "<option value='".$prev."'>".$prevlang." - ".$prev."</option>";
}

foreach ($categories as $category) {
	$select .= "<option value='".$category['name']."'>".$category['name']."</option>";
}

$select .= "</select>";

return $select;

}

function reorder_games() {

global $db;

$games = get_games("sort=ASC&order=order&active=-all-");

$i = 1;
foreach ($games as $game) {
	$game['order'] = $i;

	$db->query("UPDATE games
	SET `order`='".$game['order']."'
	WHERE `id`='".$game['id']."'");

	++$i;
}

}

function add_submission() {

global $db;

$do = true;

$name = mysql_escape_string($_POST['name']);
$desc = mysql_escape_string($_POST['desc']);
$cat = mysql_escape_string($_POST['cat']);
$swf = mysql_escape_string($_POST['swf']);
$thumb = mysql_escape_string($_POST['thumb']);
$authorname = mysql_escape_string($_POST['authorname']);
$authorsite = mysql_escape_string($_POST['authorsite']);

$authorsite = str_replace("http://", "", $authorsite);

$time = time();
$uf = $cfg['instdir']."uploadfiles/";

$nameid = md5($name.$desc.$time);
$nameid = substr($nameid, 0, ;

$gext = 'swf';
$text = 'png';

$gext = substr(strrchr($swf, "."), 1);
$text = substr(strrchr($thumb, "."), 1);

$tname = $uf.$nameid.".".$text;
$gname = $uf.$nameid.".".$gext;

copy($swf, $gname);
copy($thumb, $tname);

// image
if ($text == "jpg") {
	$text = "jpeg";
}

$gdcall = "imagecreatefrom".$text;

if (function_exists($gdcall)) {
	if (!($im = $gdcall($tname))) {
		echo "Error in image data.";
		$do = false;
	} else {

		$imgsize = getimagesize($tname);
		$iwidth=$imgsize['0'];
		$iheight=$imgsize['1'];

		$twidth = get_game_config("name=twidth");
		$theight = get_game_config("name=theight");

		$newim = imagecreatetruecolor($twidth, $theight);

		imagecopyresized(
		$newim,
		$im,
		0,
		0,
		0,
		0,
		$twidth,
		$theight,
		$iwidth,
		$iheight);

		if (!imagepng($newim, $cfg['instdir']."img/".$nameid.".png")) {
			echo "Error writing image.";
			$do = false;
		}


	}

} else {
	echo 'Your image format is not supported. Please use a PNG, GIF, or JPEG.';
	$do = false;
}
//////////////////

if ($gext == "swf") {
	$type = "SWF";
} else if ($gext == "dcr") {
	$type = "DCR";
} else {
	$do = false;
	echo "Error, you must upload an SWF or a DCR";
}

if ($type == "SWF" || $type == "DCR") {

	copy($gname, $cfg['instdir']."swf/".$nameid.".".$gext);

	$width = get_game_config("name=defgwidth");
	$height = get_game_config("name=defgheight");

	if ($type == 'SWF') {
		$wh = getimagesize($gname);
		if ($wh != false) {
			$width = $wh[0];
			$height = $wh[1];
		}
	}

}

/////
$gameurl = "";
$customcode = "";
$instructions = "";
$keywords = "";
/////

if ($do == true) {

	unlink($gname);
	unlink($tname);

	$query = "
	INSERT INTO `games` ( `id` , `nameid` , `name` , `desc` , `time` , `width` , `height` , `cat` , `type` , 	`authorsite` , `authorname` , `gameurl` , `code`, `playcount` , `flags`, `instructions`, `keywords` , `order` , `active` )
	VALUES (
		'', '".$nameid."', '".$name."', '".$desc."', '".$time."', '".$width."', '".$height."', '".$cat."', '".$type."', '".$authorsite."', '".$authorname."', '".$gameurl."', '".$customcode."', '0', '', '".$instructions."', '".$keywords."' , '-1' , 'No'
	)
	";

	$db->query($query);

	reorder_games();

	echo "Thank you for your submission. It will be added to [sitetitle] as soon as an administrator approves it.";

} else {
	echo "There was an error with your submission";
}

}



?>

 

Link to comment
https://forums.phpfreaks.com/topic/39835-imagecreate-error/#findComment-192622
Share on other sites

I only quickly looked at the code, but if its bumping out to that else automatically, my guess is that it has to be something to do with the if(function_exists($gdcall)) line.

<?php
$text = "jpeg";
$gdcall = "imagecreatefrom".$text;
if(function_exists($gdcall))
{
echo "True";
}
?>

 

This should return true, so my guess would be that $text is not behaving as you thought it would. I would try echoing $test before, during, and after the if just to see how it's acting.

Link to comment
https://forums.phpfreaks.com/topic/39835-imagecreate-error/#findComment-192642
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.