Welcome Guest, Not a member yet? Register   Sign In
I can't write on an image
#1

[eluser]Alhazred[/eluser]
I have to dynamically write some texts on an image and show it on the page.

I've put the image into a folder "static/images" and the font file into a folder "static/fonts" and to make a try I've written this function into a controller
Code:
public function write_img()
{
header('Content-type: image/png');

$png_image = imagecreatefrompng(base_url('static/images/calendar-icon.png'));

$white = imagecolorallocate($png_image, 68, 68, 68);

$font_path = base_url('static/fonts/arial.ttf');

$text = "25";

imagettftext($png_image, 25, 0, 75, 300, $white, $font_path, $text);

imagepng($png_image);

imagedestroy($png_image);
}
The problem is that the image is not shown on the page.
Firefox says that the image contains errors, Chrome and Opera show the "image not fond" icon, Safari shows a blank page, Internet Explorer says:
<p>Severity: Warning</p>
<p>Message: imagettftext(): Invalid font filename</p>
<p>Filename: controllers/home.php</p>
<p>Line Number: 83</p>

</div>‰PNG

and follows a text which looks the content of an image file opend on a text editor.

As IE says it seem that the font file is invalid, but what does that mean? The file is there.
#2

[eluser]Alhazred[/eluser]
Some news.
If I put this code inside a controller the image appears
Code:
function create_img()
{
    $img   = imagecreatefrompng(realpath('static/images/calendar-icon.png'));
    $text_colour = imagecolorallocate( $img, 68, 68, 68 );
    $font_path  = realpath('static/fonts/monosb.TTF');
  
    imagettftext($img, 250, 0, 65, 475, $text_colour, $font_path, '25');

    header( "Content-type: image/png" );
    imagepng( $img );
    imagedestroy( $img );
}

If I put the same code (so it is correct to create and show an image) into a model function and then I call it into a view in this way
Code:
<img src='&lt;?php $this-&gt;my_model-&gt;create_img() ?&gt;' />
on the page appears only the message that the image has some error.

Have you any idea about how to solve this problem?




Theme © iAndrew 2016 - Forum software by © MyBB