Hello all,

I am trying to merge two images using PHP and then to save the result in the database (as BLOB). However, the script always saves a blob of 1B size.

Here's the code:
Code:
if ($_FILES['userfile']['error'] == 0 && $_FILES['userfile']['size'] > 0) {
            $uploaddir = "images/";
            $fileName = $_FILES['userfile']['name'];
            $tmpName  = $_FILES['userfile']['tmp_name'];
            $fileSize = $_FILES['userfile']['size'];
            $fileType = $_FILES['userfile']['type'];

            define( 'WATERMARK_OVERLAY_IMAGE', base_url().'img/site_images/profile_pic_overlay.png' );

                
                list( $source_width, $source_height, $source_type ) = getimagesize( $tmpName );
                
                if ($source_type) {
                    switch ( $source_type )
                    {
                        case IMAGETYPE_GIF:
                         $source_gd_image = imagecreatefromgif( $tmpName );
                         break;
                        case IMAGETYPE_JPEG:
                         $source_gd_image = imagecreatefromjpeg( $tmpName );
                         break;
                        case IMAGETYPE_PNG:
                         $source_gd_image = imagecreatefrompng( $tmpName );
                         break;
                        default:
                         return false;
                    }
                    
                    $overlay_gd_image = imagecreatefrompng( WATERMARK_OVERLAY_IMAGE );
                    $overlay_width = imagesx( $overlay_gd_image );
                    $overlay_height = imagesy( $overlay_gd_image );
                    
                    
                    $temp = imagecopymerge(
                        $source_gd_image,
                        $overlay_gd_image,
                        0,
                        0,
                        0,
                        0,
                        $overlay_width,
                        $overlay_height,
                        75
                    );
                    
                    $content = imagejpeg( $source_gd_image );
                    $fileType = "image/jpeg";
    
                    imagedestroy( $source_gd_image );
                    imagedestroy( $overlay_gd_image );
         }
}
and then need to save $content in a database table (which works when I don't try to merge the images.

Any ideas?

Many thanks.

Shmoyko