PHP GD Library无法使用函数合并到图像

时间:2013-12-10 05:40:51

标签: php gd gdlib

这是我要合并到图像的php类

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); 
?>

如果我运行 createing_obj.php 我只选择一个图像文件,而不是合并两个图像。如果我在imagecreatefrompng()内使用url,它可以正常工作,而不是类。

请问好吗?

1 个答案:

答案 0 :(得分:1)

function barchart(){
    return $canvas;
}

或(如果要将此图层图像保存到磁盘):

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

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

    return $path.$filename;
}

对其他(绘图)课也这样做..