2

Hi have 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 the image within an image tag like the following

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

but somehow it's always rendering garbled code to the screen and not the result I want. Is this at all possible? And how without using a seperate file, I want this to remain within a function or method.

hakre
  • 193,403
  • 52
  • 435
  • 836
Elitmiar
  • 35,072
  • 73
  • 180
  • 229

2 Answers2

5

You need to render the image in a separate resource. There is no good way of adding the image data inside the HTML document. (Anybody thinking of recommending data: URIs: It's a terrible idea.)

<img src="renderBusinessCard.php?param1=1&param2=2">
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Thx, then I need to do it this way, thank you. What I'll do is I rather create the image in a folder and then render it from there, due to the structure of the application "long story" – Elitmiar Mar 09 '11 at 06:30
0

It may be better to keep the $details array in session data if it's not too big. Then calling will call the script and associate the correct details data.

Colin
  • 11
  • 1