PHP GD Library cannot Merge to image using function

164 views Asked by At

This is my php class to merge to images

mergepic.php

class mergepic{
    public function merge_barchart_drawing($object,$obj)
    {
     $src = imagecreatefrompng($obj->barchart());
        $dest = imagecreatefrompng($object->drawing());
        //$src = imagecreatefrompng('http://localhost/graph/barchart.php?barchart='.$_GET['barchart'].'&max='.$_GET['max'].'&digit='.$_GET['digit']);
        //$dest = imagecreatefrompng('http://localhost/graph/drawing.php?drawings='.$_GET['drawings'].'&max='.$_GET['max'].'&digit='.$_GET['digit']);
        imagealphablending($dest, false);
        imagesavealpha($dest, true);
        imagecopymerge($dest, $src, 10, 9, 0, 9, 700, 500, 100); //have to play with these numbers for it to work for you, etc.
        header('Content-Type: image/png');
        imagepng($dest); 
        imagedestroy($dest); 
        imagedestroy($src); 
    }
}

creating_obj,php

<?
include('drawing.php');
include('barchart.php');
include('mergepic_class.php');
$draw = new drawgraph();
$barchart = new barchart_graph();
$merge_draw = new mergepic();
$merge_draw_bar = $merge_draw->merge_barchart_drawing($draw,$barchart); 
?>

If i run createing_obj.php i am geting only one image file its not mergeing two images. Instead of class if i use url inside imagecreatefrompng() it working fine.

Any idea please ?

1

There are 1 answers

0
Qarib Haider On BEST ANSWER
function barchart(){
    return $canvas;
}

OR (If you want to save this layer image to disk):

function barchart(){
    $path = {path where to save file};
    $filename = {filename to save and extension};

    imagepng($canvas,$path.$filename);

    return $path.$filename;
}

Do this same for the other(drawing) class too..