mxch
mxch

Reputation: 865

PHP + CodeIgniter: ImageCreateFromJPEG not loading image

Hi I'm new to PHP and CodeIgniter and I have the following problem

I have a controller in which I want to call a PHP funnction that is defined on another .php.

This is the function:

function createNote($note_text){
     header('Content-type: image/jpeg');
     $note = "./application/controllers/notes/note.jpg";
     $rImg = ImageCreateFromJPEG($note);
     imagejpeg($rImg);

    //After this I want to use the "imagettftext" function to insert the $note_text in
    //the image   
}

This is suposed to load that image and show it (I guess) but it doesn't, instead it shows the following:

enter image description here I know the path to the image is correct because if I change it the ImageCreateFromJPEF returns an error saying that the image was not found...

Any ideas?

Thanks in advance!

Upvotes: 1

Views: 2300

Answers (2)

mxch
mxch

Reputation: 865

After VictorKilo answered I searched how to set the .htaccess file.

This question helped me a lot: How do I write a .htaccess file to make CodeIgniters URL routing work?

Before, my .htaccess had "Deny from all", now it looks like this:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|scripts|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Hope this helps someone else. Thanks for your time and answers Umair Iqbal, VictorKilo and Robbie.

Upvotes: 0

Robbie
Robbie

Reputation: 17710

Troubleshooting tips:

  1. You should check the output to ensire that you're not adding any characters before or after the ouptput.
  2. Add "exit" after the imageJPEG() to prevent further execution (it'll look for a view somewhere).
  3. Do a var_dump($rImg) and view (as normal file, comment out the header line) to check the image object is being loaded correctly. As Umair said in comment, use an absolute path or base of application root to make sure you are loading the file in correctly.

Upvotes: 1

Related Questions