save bitmapData with php to 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
relief8
Forum Newbie
Posts: 13
Joined: Fri Jan 25, 2008 4:28 pm

save bitmapData with php to server

Post by relief8 »

Everah | Please use the appropriate bbCode tags when posting code in the forums. For regular code, you can use [code]. For PHP, you can use [code=php] or [php] or [syntax="php"].

I am using the code below to open a new html window and display bitmapData as a jpeg. Does anyone know what to change in this code to make it save the jpeg to a directory on the server?

Code: Select all

<?php
    $data = explode(",", $_POST['img']);
    $width = $_POST['width'];
    $height = $_POST['height'];
    $image=imagecreatetruecolor( $width ,$height );
    $background = imagecolorallocate( $image ,0 , 0 , 0 );
    //Copy pixels
    $i = 0;
    for($x=0; $x<=$width; $x++){
        for($y=0; $y<=$height; $y++){
            $int = hexdec($data[$i++]);
            $color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
            imagesetpixel ( $image , $x , $y , $color );
        }
    }
    //Output image and clean
    header( "Content-type: image/jpeg" );
    ImageJPEG( $image );
    imagedestroy( $image ); 
    
?>
Everah | Please use the appropriate bbCode tags when posting code in the forums. For regular code, you can use [code]. For PHP, you can use [code=php] or [php] or [syntax="php"].
dayyanb
Forum Commoner
Posts: 46
Joined: Wed Jan 23, 2008 12:34 am

Re: save bitmapData with php to server

Post by dayyanb »

http://us3.php.net/manual/en/function.imagejpeg.php
bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )
So you would use:

Code: Select all

 
ImageJPEG( $image , '/filepath/filename.jpg' );
 
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: save bitmapData with php to server

Post by RobertGonzalez »

Moved to PHP - Code.
Post Reply