Jump to content
MakeWebGames

imagecopymerge problems?


Sim

Recommended Posts

I'm trying to take an image and extract every 32x32 image from it. heres what I got. every image i upload is divisible by 32 so I know thats not the problem. ever image I uploaded gets created as preview.png so i know thats not the problem either.

 

			mkdir("../tiles/$names", 0777);
		$file_typ = array();
		$file_typ =  explode('.',strtolower($_FILES["file"]["name"]));
		$file_type = $file_typ[count($file_typ)-1];
		if($file_type == "png")
		{
			move_uploaded_file($_FILES["file"]["tmp_name"], "../tiles/$names/preview.png");
			$src = imagecreatefrompng("../tiles/$names/preview.png");

			$w = imagesx($src) / 32; 
			$h = imagesy($src) / 32;
			if( (is_int($w)) && (is_int($h)) )
			{

				 /* Create a blank image */
				for($x=0; $x < $h - 32; $x=$x+32)
				{
					for($y=0; $y < $w - 32; $y=$y+32)
					{
						$im  = imagecreate(32, 32);
						imagecopymerge($im $src, 0, 0, $x,$y, $x+32, $y + 32, 0);
						imagepng($im ,"../tiles/$names/$x-$y.png"); 
					}
				}
			}
		}
Link to comment
Share on other sites

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.   Paste as plain text instead

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