Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

JAKZ AIZZAT
JAKZ AIZZAT
7,813 Points

Why I can't output the image in rotate?

<?php 

$img = imagecreatefromjpeg('simpletext.jpg');
$imgRotated = imagerotate($img, 45,-1);

imagejpeg($imgRotated,'newsimpletext.jpg',100);


?>



<img src="simpletext.jpg" />

<hr>

<img sec="newsimpletext.jpg" />

I want to output the image in rotate version but it has error

Warning: imagejpeg() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\developphp\index.php on line 6

2 Answers

imagerotate actually will return to you a boolean (false) if it fails, so the problem is likely either there or in setting the initial $img. Are you sure it's loading an image into that variable?

JAKZ AIZZAT
JAKZ AIZZAT
7,813 Points

Ya. Im sure. Im trying to echo the original image at bottom of line code and its work.

Actually i'm following this tutorial : http://www.developphp.com/view.php?tid=1138

Have you tried it with a different jpeg image? I just tried your code out and it works for me. Do you see any errors in your error_log for the call to imagerotate?

JAKZ AIZZAT
JAKZ AIZZAT
7,813 Points

I have tried with other image and its still doesn't work. :(

This is its error: Warning: imagejpeg() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\developphp\index.php