kharddie Posted August 29, 2007 Share Posted August 29, 2007 hey guys, I have this php code that receives variables form flash to create image which works fine. what i want to do is save that image after its been created on my server instead of showing it as is in the code below. how do i go abut that to save it in this folder -----flashimages/ thanks guys. <?php error_reporting(0); /** * Get the width and height of the destination image * from the POST variables and convert them into * integer values */ $w = (int)$_POST['width']; $h = (int)$_POST['height']; // create the image with desired width and height $img = imagecreatetruecolor($w, $h); // now fill the image with blank color // do you remember i wont pass the 0xFFFFFF pixels // from flash? imagefill($img, 0, 0, 0xFFFFFF); $rows = 0; $cols = 0; // now process every POST variable which // contains a pixel color for($rows = 0; $rows < $h; $rows++){ // convert the string into an array of n elements $c_row = explode(",", $_POST['px' . $rows]); for($cols = 0; $cols < $w; $cols++){ // get the single pixel color value $value = $c_row[$cols]; // if value is not empty (empty values are the blank pixels) if($value != ""){ // get the hexadecimal string (must be 6 chars length) // so add the missing chars if needed $hex = $value; while(strlen($hex) < 6){ $hex = "0" . $hex; } // convert value from HEX to RGB $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); // allocate the new color // N.B. teorically if a color was already allocated // we dont need to allocate another time // but this is only an example $test = imagecolorallocate($img, $r, $g, $b); // and paste that color into the image // at the correct position imagesetpixel($img, $cols, $rows, $test); } } } // print out the correct header to the browser header("Content-type:image/jpeg"); // display the image imagejpeg($img, "", 90); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67262-solved-save-php-generated-images/ Share on other sites More sharing options...
Fadion Posted August 30, 2007 Share Posted August 30, 2007 imagejpeg($im, 'flashimages/mynewimage.jpg', 80); Quote Link to comment https://forums.phpfreaks.com/topic/67262-solved-save-php-generated-images/#findComment-337437 Share on other sites More sharing options...
kharddie Posted August 30, 2007 Author Share Posted August 30, 2007 thanx for that i have replaced the last bit of the code with this imagejpeg($im, 'proofing_files_edited_by_clients/mynewimage.jpg', 90); but still no luck and yes the folder --proofing_files_edited_by_clients--has read write permission <?php error_reporting(0); /** * Get the width and height of the destination image * from the POST variables and convert them into * integer values */ $w = (int)$_POST['width']; $h = (int)$_POST['height']; // create the image with desired width and height $img = imagecreatetruecolor($w, $h); // now fill the image with blank color // do you remember i wont pass the 0xFFFFFF pixels // from flash? imagefill($img, 0, 0, 0xFFFFFF); $rows = 0; $cols = 0; // now process every POST variable which // contains a pixel color for($rows = 0; $rows < $h; $rows++){ // convert the string into an array of n elements $c_row = explode(",", $_POST['px' . $rows]); for($cols = 0; $cols < $w; $cols++){ // get the single pixel color value $value = $c_row[$cols]; // if value is not empty (empty values are the blank pixels) if($value != ""){ // get the hexadecimal string (must be 6 chars length) // so add the missing chars if needed $hex = $value; while(strlen($hex) < 6){ $hex = "0" . $hex; } // convert value from HEX to RGB $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); // allocate the new color // N.B. teorically if a color was already allocated // we dont need to allocate another time // but this is only an example $test = imagecolorallocate($img, $r, $g, $b); // and paste that color into the image // at the correct position imagesetpixel($img, $cols, $rows, $test); } } } //save image imagejpeg($im, 'proofing_files_edited_by_clients/mynewimage.jpg', 90); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67262-solved-save-php-generated-images/#findComment-337472 Share on other sites More sharing options...
MadTechie Posted August 30, 2007 Share Posted August 30, 2007 1. welcome to the forum 2. please use code tags (the [code.][/code.]) without the dot 3. GuiltyGear, is correct, check the path Quote Link to comment https://forums.phpfreaks.com/topic/67262-solved-save-php-generated-images/#findComment-337473 Share on other sites More sharing options...
Fadion Posted August 30, 2007 Share Posted August 30, 2007 try: imagejpeg($img, 'proofing_files_edited_by_clients/mynewimage.jpg', 90); as your image recourse is $img, not $im Quote Link to comment https://forums.phpfreaks.com/topic/67262-solved-save-php-generated-images/#findComment-337474 Share on other sites More sharing options...
kharddie Posted August 30, 2007 Author Share Posted August 30, 2007 Thanks guys for ur help it works Quote Link to comment https://forums.phpfreaks.com/topic/67262-solved-save-php-generated-images/#findComment-337483 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.