Want to make an image without saving it to disk using PHP GD libs

Hi has the following function

function renderBusinessCard($details){
        //Getting the template for the business card
        $filename = Templates::model()->getTemplateFileName($details['BusinessCards']['dp_id']);
        header("Content-type: image/jpeg");

        $image = $_SERVER['DOCUMENT_ROOT'].'resources/templates/'.$filename;


//        header("Content-Type: image/jpeg");
        //Getting the width and height of the image
        list($width,$height) = getimagesize($image);


//echo $width;die;
        //Creating a copy of a loaded image
        $create = imagecreatefromjpeg($image);


        //Creating a blank template to work from
        $template = imagecreatetruecolor($width,$height);
        imagecopyresized($template, $create, 0, 0, 0, 0, $width, $height, $width, $height);

        imagejpeg($template, null, 100);

    }

What I want to achieve is to display an image in an image tag, like the following

<img src="<?php renderBusinessCard($details); ?>"

but somehow it always displays the garbled code on the screen, not the result that I want. Is it even possible? And as without using a separate file, I want it to remain in a function or method.

+3
source share
2 answers

You need to display the image in a separate resource. There is no good way to add image data to an HTML document. (Anyone thinking of recommending data:URIs: This is a terrible idea.)

<img src="renderBusinessCard.php?param1=1&param2=2">
+6
source

, $details , . script .

0

All Articles