image - php cannot be displayed because it contains errors -
i getting next error when run script php cannot displayed because contains errors
the script, takes file, resizes outputs screen , file.
url_example: localhost/testimage.php?img=img_592_121_200.jpg
i have read posts , tried proposed solutions. failed
the file not output screen/browser can gets save file.
here code, stripped white space off , empty lines. , hard-coded file name within script
**am starting suspect setup, not sure how/where start looking
edit : simplified go output screen only
testimage.php
<?php //session_start(); //ob_start(); ini_set("display_errors", "1"); error_reporting(e_all); header('content-type:image/jpeg'); //$cachefile="mypicxxx.jpg"; //$cache_dir="cache/1/592/"; $img_dir="webspace/1/592/"; $img="img_592_121.jpg"; $id="$img_dir$img"; $src=imagecreatefromjpeg($id); $new_width=200; $new_height=77; $width=600; $height=1001; $w_src=600; $h_src=1001; $img=imagecreatetruecolor($new_width,$new_height); imagecopyresampled($img,$src,0,0,0,0,$new_width,$new_height,$w_src,$h_src); imagejpeg($img,null,45); //$cachefile=$cache_dir.$cachefile; //imagejpeg($img,$cachefile,45); imagedestroy($src); imagedestroy($img); //ob_end_flush(); ?>
have checked no output sent before header? couple of things can try:
move header() function top. remove caching (ob_start) , see if can create work without first. as utilize ob_start, guess want utilize ob_end_flush(); @ end? try utilize null sec param imagejpeg() raw output instead of writing file. (could related write permissions)update sure checked file pointing exists/or path valid? works on localhost, running default xamp installation (php3.5.1)
ini_set("display_errors", "1"); error_reporting(e_all); header('content-type:image/jpeg'); //$cachefile="mypicxxx.jpg"; //$cache_dir="cache/1/592/"; $img_dir="webspace/1/592/"; $img="test.jpg"; $src=imagecreatefromjpeg($img); $new_width=200; $new_height=77; $width=600; $height=1001; $w_src=600; $h_src=1001; $img=imagecreatetruecolor($new_width,$new_height); imagecopyresampled($img,$src,0,0,0,0,$new_width,$new_height,$w_src,$h_src); imagejpeg($img,null,45); //$cachefile=$cache_dir.$cachefile; //imagejpeg($img,$cachefile,45); imagedestroy($src); imagedestroy($img);
php image gd dynamic-image-generation
No comments:
Post a Comment