Jump to content

Image Error


ivoilic

Recommended Posts

So I am trying to generate an image based off of a form filled out by the user.  It generates the image which is saved to a folder but the image does not show up in the browser.  However when I comment out the header there are no errors!

Here is the message I get: "The Image: 'http:// localhost/whatever.php' cannot be displayed because it contains errors.

 

Here is all of the code I included it all because I have no clue what is causing it.

<?php
require 'connect.inc.php';
require 'core.inc.php';
//Get all info from cardcrafter.php
  $title = $_REQUEST['title'] ;
        /* $desc = $_REQUEST['desc'] ; */
 $cardart = $_REQUEST['cardart'] ;
 $atk = $_REQUEST['atk'];
$def = $_REQUEST['def'];
        $acc = $_REQUEST['acc'];
        $hp = $_REQUEST['hp'];

	//$quo = ($desc == "") ? "" : "\"";
//Serial Number Generation (Needs to be shortned with a function)
	$ser_num = array("1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$num1 = rand(0,count($ser_num)-1);
$numf1 = wordwrap($ser_num[$num1],1,"\n", true);
$num2 = rand(0,count($ser_num)-1);
$numf2 = wordwrap($ser_num[$num2],1,"\n", true);
$num3 = rand(0,count($ser_num)-1);
$numf3 = wordwrap($ser_num[$num3],1,"\n", true);
$num4 = rand(0,count($ser_num)-1);
$numf4 = wordwrap($ser_num[$num4],1,"\n", true);

$num5 = rand(0,count($ser_num)-1);
$numf5 = wordwrap($ser_num[$num5],1,"\n", true);
$num6 = rand(0,count($ser_num)-1);
$numf6 = wordwrap($ser_num[$num6],1,"\n", true);
$num7 = rand(0,count($ser_num)-1);
$numf7 = wordwrap($ser_num[$num7],1,"\n", true);
$num8 = rand(0,count($ser_num)-1);
$numf8 = wordwrap($ser_num[$num8],1,"\n", true);

$num9 = rand(0,count($ser_num)-1);
$numf9 = wordwrap($ser_num[$num9],1,"\n", true);
$num10 = rand(0,count($ser_num)-1);
$numf10 = wordwrap($ser_num[$num10],1,"\n", true);
$num11 = rand(0,count($ser_num)-1);
$numf11 = wordwrap($ser_num[$num11],1,"\n", true);
$num12 = rand(0,count($ser_num)-1);
$numf12 = wordwrap($ser_num[$num12],1,"\n", true);

$serial = ''.$numf1.''.$numf2.''.$numf3.''.$numf4.'-'.$numf5.''.$numf6.''.$numf7.''.$numf8.'-'.$numf9.''.$numf10.''.$numf11.''.$numf12.'';
//$serial = '569B-U31Z-QOKW';

	// array of random abilites (No longer needed for now)
//$ability = array("When $title is spawned draw a card", "Any card damaged by $title is delt 1 damage every turn");
// generate a random number with range of # of array elements
//$pos = rand(0,count($ability)-1);
// get the ability and word wrap it
//$ability_f = wordwrap($ability[$pos],40,"\n", true);

$query="SELECT `serial` FROM `Cards` WHERE `serial`='$serial'";
				$query_run=mysql_query($query);

				if(mysql_num_rows($query_run)>=1) {
					header('Location: cardcrafter.php');	
				} else {        
if ($title == ""){echo "Your card needs a name!";}
else {if ($atk <=0 || $def <=0 || $acc <=0 || $hp <= 0) {echo "All skills need at least one skill point!";}
else {
//Calculate total points
$points = $atk + $def + $acc + $hp;
$user_id = getuserfield('id');
$username = getuserfield('username');

$query = "INSERT INTO `Cards` VALUES ('','".mysql_real_escape_string($user_id)."','".mysql_real_escape_string($title)."','".mysql_real_escape_string($cardart)."','".mysql_real_escape_string($serial)."','".mysql_real_escape_string($atk)."','".mysql_real_escape_string($def)."','".mysql_real_escape_string($acc)."','".mysql_real_escape_string($hp)."','".mysql_real_escape_string($username)."','')";

if($query_run = mysql_query($query)) {
} else {
	echo mysql_error();
}
// Load Template
$image = imagecreatefrompng ( "../Card_Images/water.png" );
$filename = "../Art/eyebook.jpg";




// get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = "638";
$new_height = "450";

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$art = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $art, 0, 0, 0, 0, $new_width, $new_height, $width, $height);


//Merge Background with card art
imagecopymerge($image, $image_p, 60, 130, 0, 0, 638, 450, 100);

// Path to our font file
$font = '../Joanna/MJoa';
$italic = '../Joanna/MJoaIta';
// pick color for the text
$fontcolor = imagecolorallocate($image, 0, 0, 0);

//Create Title
imagettfbbox(35, 0, $font, $title);
imagettftext($image, 35, 0, 40, 80, $fontcolor, $font, stripslashes($title));

//Create Description
/*imagettfbbox(30, 0, $italic, $desc);
imagettftext($image, 30, 0, 70, 700, $fontcolor, $italic,   stripslashes(" $quo$desc$quo "));*/
//Create Ability (Not used as of game V3)
//imagettfbbox(25, 0, $font, $ability_f);
//imagettftext($image, 25, 0, 70, 700, $fontcolor, $font,   stripslashes($ability_f));

//Points
imagettfbbox(35, 0, $font, $points);
imagettftext($image, 35, 0, 585, 80, $fontcolor, $font,  $points);
//HP
imagettfbbox(50, 0, $font, $hp);
imagettftext($image, 50, 0, 40, 1000, $fontcolor, $font, $hp);
//Attack
imagettfbbox(30, 0, $font, $atk);
imagettftext($image, 30, 0, 150, 635, $fontcolor, $font, $atk);
//Defense
imagettfbbox(30, 0, $font, $def);
imagettftext($image, 30, 0, 360, 635, $fontcolor, $font, $def);
//Accuracy
imagettfbbox(30, 0, $font, $acc);
imagettftext($image, 30, 0, 560, 635, $fontcolor, $font, $acc);
//Serial
imagettfbbox(25, 0, $font, $serial);
imagettftext($image, 25, 0, 150, 1000, $fontcolor, $font,   stripslashes($serial));

// get new dimensions
$imagewidth = 754;
$imageheight = 1054;
$final_width = "251";
$final_height = "351";

// Resample
$image_f = imagecreatetruecolor($final_width, $final_height);
imagecopyresampled($image_f, $image, 0, 0, 0, 0, $final_width, $final_height, $imagewidth, $imageheight);

// output image to the browser
header('Content-type: image/png');
imagepng($image_f, '../Cards/'.$serial.''.$title.'.png');






// delete the image resource
imagedestroy($image); 
imagedestroy($art);
imagedestroy($image_p);
imagedestroy($image_f);




}}}
    ?>


Link to comment
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.