We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

PHP In template fails and creates weird characters

Development and Programming

adro's avatar
adro
110 posts
13 years ago
adro's avatar adro

I’m trying to use imagejpeg with PHP to turn a text string into a jpeg. When I run the code on my server in a regular PHP file (outside of EE) it works perfectly. But when I try to render the code in an EE template I get a whole bunch of weird characters (see attachment). For reference, this is the code:

<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);

// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');

// Output the image
imagejpeg($im);

// Free up memory
imagedestroy($im);
?>

I have PHP enabled for the template and I’ve tried both input and output with the same results. Using EE 2.4.0.

       
Shane Eckert's avatar
Shane Eckert
7,174 posts
13 years ago
Shane Eckert's avatar Shane Eckert

Hello adro,

Thank you for posting your question on the forums.

I was able to reproduce that this does not work. But it’s a bit outside of support as we do not support custom PHP. I would like to move this to development and programming to see if the community can help you with this.

Thanks again for asking your question!

Cheers,

       
the3mus1can's avatar
the3mus1can
426 posts
13 years ago
the3mus1can's avatar the3mus1can

Try adding an exit; right after the imagedestroy($im).

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Hi Adro,

your code is correct. could you please check if “GD Support” and “JPEG Support” are enabled?

Because PHP’s image creation functions need “GD library”.

Best Regards,

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.