Jpeg creation on server

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
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Jpeg creation on server

Post by ianhull »

Hi Guys,

I am currently working with Flash and PHP to create .jpg images on the server.
Everything is working fine but now I need to retrieve the file name and path of the created image.

Do any of you know how to do this from the code below?

Any help will be greatly appreciated.

Thanks in advance.

Code: Select all

<?php
$w = (int)$_POST['width'];
$h = (int)$_POST['height'];

$img = imagecreatetruecolor($w, $h);

imagefill($img, 0, 0, 0xFFFFFF);

$rows = 0;
$cols = 0;

for($rows = 0; $rows < $h; $rows++){

	$c_row = explode(",", $_POST['px' . $rows]);
	for($cols = 0; $cols < $w; $cols++){

		$value = $c_row[$cols];

		if($value != ""){

			$hex = $value;
			while(strlen($hex) < 6){
				$hex = "00" . $hex;
			}

			$r = hexdec(substr($hex, 0, 2));
			$g = hexdec(substr($hex, 2, 2));
			$b = hexdec(substr($hex, 4, 2));

			$test = imagecolorallocate($img, $r, $g, $b);

			imagesetpixel($img, $cols, $rows, $test);
		}
	}
}
?>
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Use the imagejpeg() ( http://www.php.net/imagejpeg ) function to save the image to whereever you want .. with whatever filename you want.
Post Reply