Jump to content

PHP gd help


SmoshySmosh

Recommended Posts

What I am trying to do is get the script to recolor the hair on some images from a palette file, but i am having some issues, I get the script to run with no errors but I don't get any image, Here is the code can I get some help?

 

<?php
$hair = $_GET['hair'];
$color = $_GET['color'];
$imgname = "$hair.gif";
$image = imagecreatefromgif  ( $imgname  );
$palette_file = fopen("$color.pal", "rb");
$contents = fread($palette_file, filesize($imgname));
$i=0;
while ($i<=255) {
$red = fread($palette_file, 1);
$green = fread($palette_file, 1);
$blue = fread($palette_file, 1);
imagecolorset($image, $i, $red, $green, $blue);
//imagecolorset($palette_file, $i, $red, $green, $blue);
$i++;
$im = @imagecreatefromgif ($imgname); /* Attempt to open */
    if (!$im) { /* See if it failed */
       $im = imagecreatetruecolor (150, 30); /* Create a blank image */
       $bgc = imagecolorallocate ($im, 255, 255, 255);
       $tc = imagecolorallocate ($im, 0, 0, 0);
       magefilledrectangle ($im, 0, 0, 150, 30, $bgc);
        /* Output an errmsg */
     imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc);
   }
  return $im;
}
header("Content-Type: image/gif");
$img = LoadGif("$hair.gif");
imagegif($img);
imagedestroy($img);
?>

http://www.qq-ro.com/images/hairs/M/1.gif Here is a color hair.

http://www.qq-ro.com/images/hairs/M/9.pal Here is color 9 for that hair.

 

I hope this helps, I really need to get this done.

 

Forgot to add a link to the page heh... http://www.qq-ro.com/images/hairs/M/test.php

Link to comment
Share on other sites

<?php
$gender = $_GET['gender'];
$gender2 = $_GET['gender2'];
$hair = $_GET['hair'];
$color = $_GET['color'];
$imgname = "./hairs/$gender/$hair.gif";
$image = imagecreatefromgif($imgname);
$palette_file = fopen("./palette/$gender/".$hair."_".$gender2."_".$color.".pal", "rb");
$contents = fread($palette_file, filesize($imgname));
$i=0;
while ($i<=254) {
$red = fread($palette_file, 1);
$green = fread($palette_file, 1);
$blue = fread($palette_file, 1);
imagecolorset($image, $i, $red, $green, $blue);
$i++;
}
if($image) {
header("Content-Type: image/gif");
ImagePNG($image);
imagedestroy($image);
}
?>

Here is the code now, but it spits out the image as all black

http://www.qq-ro.com/images/test.php?hair=1&color=11&gender=M&gender2=m&

All I want is for the palette to change the hair color on the image

http://www.qq-ro.com/images/hairs/M/1.gif

 

Get it now? Anyone help?

Link to comment
Share on other sites

just messing around with your address...

 

the address http://www.qq-ro.com/images/test.php?hair=1&color=21&gender=M outputs this:

Warning: fopen(./palette/M/1__21.pal) [function.fopen]: failed to open stream: No such file or directory in /mnt/local/home/holoc/qq-ro.com/images/test.php on line 8
.............
Warning: Cannot modify header information - headers already sent by (output started at /mnt/local/home/holoc/qq-ro.com/images/test.php:13) in /mnt/local/home/holoc/qq-ro.com/images/test.php on line 30
‰PNG  ��� IHDR���������HÍ_á���9PLTE���������������������������������������������������������¼vP=���tRNS�@æØf��IDAT(‘}’‹v„ D-ÝðhLþÿÇv\W»mçˆJ.„0°,WÙò—þ!ú+WU¾®Ä(u#2%¾ä×CÄÎ{A0¶UÍA¢›^Öq7ÛVÃþŒq6 u5p‹Ew�w 0 h–j½ãte62ô}”Ò©`mªc¤Ž|ƒÄ†ödœFdO‚]ÙÌ¥O„dž6†3ôI¤úAû¨â@¨ù´h×RŒÌá)=T8ˆm"ZZçÇa£ÒpLBp 0Ôsœ &&(ñ«£ˆã\tKu š÷T?í

 

you should fix that...

Link to comment
Share on other sites

i have used this to verify that a file is there:

	if ((empty($_GET['page'])))
	{
	include "inc/main.php";
	}
else
	{
	include "inc/dbconnect.php";
	$page=(stripslashes(htmlentities(mysql_real_escape_string($_GET['page']))));
	if (!file_exists("inc/" . $_GET['page'] . ".php")) 
		{
		echo "Error, page does not exist.";
		die();
		}
	else
		{
		include "inc/".$page.".php";
		}

 

you could do something like that...

 

if (($_GET[gender]=x) || ($_GET[gender]=X) || ($_GET[gender]=y) || ($_GET[gender]=Y)
     {
     echo "cool dude!";
     }
else
     {
     echo "you smell like cheese";
     }

Link to comment
Share on other sites

i have used this to verify that a file is there:

	if ((empty($_GET['page'])))
	{
	include "inc/main.php";
	}
else
	{
	include "inc/dbconnect.php";
	$page=(stripslashes(htmlentities(mysql_real_escape_string($_GET['page']))));
	if (!file_exists("inc/" . $_GET['page'] . ".php")) 
		{
		echo "Error, page does not exist.";
		die();
		}
	else
		{
		include "inc/".$page.".php";
		}

 

you could do something like that...

 

if (($_GET[gender]=x) || ($_GET[gender]=X) || ($_GET[gender]=y) || ($_GET[gender]=Y)
     {
     echo "cool dude!";
     }
else
     {
     echo "you smell like cheese";
     }

 

Thanks for the information but do you have any info to the topic at hand? making the colors actually work?

Link to comment
Share on other sites

not exactly sure how this works, but just looking at it i think i see something...

while ($i<=254) {
$red = fread($palette_file, 1);
$green = fread($palette_file, 1);
$blue = fread($palette_file, 1);
imagecolorset($image, $i, $red, $green, $blue);
$i++;
}

 

the way that i read this is that $palette_file is 1 byte long...kinda small...

taken from php.net website:

fread() reads up to length  bytes from the file pointer referenced by handle . Reading stops as soon as one of the following conditions is met:

 

    * length bytes have been read

    * EOF (end of file) is reached

    * a packet becomes available (for network streams)

    * 8192 bytes have been read (after opening userspace stream)

 

i would think that you would have to specify a different filesize...but then again i am probably wrong...

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.