PHP GD Library cannot Merge to image using function

喜夏-厌秋 提交于 2019-12-25 03:04:33

问题


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:


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



来源:https://stackoverflow.com/questions/20487010/php-gd-library-cannot-merge-to-image-using-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!