0

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 ?

Suleman Ahmad
  • 2,025
  • 4
  • 28
  • 43
Serma
  • 44
  • 1
  • 2
  • 11
  • because the function of two classes you are calling $obj->barchart() and $object->drawing() are not available in mergepic class .. – Qarib Haider Dec 10 '13 at 10:21
  • @SyedQarib in creating_obj.php file I have passed created two object called $draw and $barchart. this two object i passed in merge_barchart_drawing($draw,$barchart) and i get it as $object and $obj in mergepic.php file is it correct way – Serma Dec 10 '13 at 10:56
  • @SyedQarib i found the problem dont know how to fix can u please help me. The prb is line $src = imagecreatefrompng($obj->barchart()); this line generate a barchart image and displayed it and program is not executing after this. but instead of object with funtion if i use url it working fine.. – Serma Dec 10 '13 at 11:57
  • your barchart() function should only return the path to image .. or an image object .. – Qarib Haider Dec 10 '13 at 12:00
  • @SyedQarib header("content-type: image/png"); imagepng($canvas); imagedestroy($canvas); return; this is how my Image file returning is this is correct – Serma Dec 10 '13 at 12:02
  • I am assuming that you are generating image with barchart() and drawing() function .. you should save the image instead and return the path to image .. to save image here is the addition to the function : imagepng([image object],[path and filename]); – Qarib Haider Dec 10 '13 at 12:03
  • yeah exactly .. donot set the header, save the image to a path and then return the path and filename from the function or if you donot want to save the image then simply return the image object – Qarib Haider Dec 10 '13 at 12:05
  • I return like this return imagepng($canvas); i removed header so that my output will be like some non human readable format data – Serma Dec 10 '13 at 12:13

1 Answers1

1
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..

Qarib Haider
  • 4,796
  • 5
  • 27
  • 38