Hyaku_ Posted January 9, 2007 Share Posted January 9, 2007 Hi!I have image saved in MySQL. For website I need to resize it, but I don't know how to open image with GD from MySQL. This is how far I got:img.php[code]<? include($_SERVER['DOCUMENT_ROOT'] . "/my_sql.php");$query = "SELECT IMG, IMG_TYPE FROM USER_ACCOUNT WHERE ID = 1";$query_exec = mysql_query($query);list($img, $type) = mysql_fetch_array($query_exec);Header("Content-Type: $type");echo $img;?>[/code]img_gd.php[code]<?header("Content-type: image/jpeg");$img = imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT'] . "/img.php");imagejpeg($img, "", 100);imagedestroy($img);?>[/code]But I get:[code]imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable errorWarning: imagecreatefromjpeg(): '/var/www/htdocs/include/img.php' is not a valid JPEG file[/code]Thanks! Link to comment https://forums.phpfreaks.com/topic/33434-solved-image-from-mysql-gd-problem/ Share on other sites More sharing options...
magic2goodil Posted January 9, 2007 Share Posted January 9, 2007 [quote][code]$img = imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT'] . "/img.php");[/code][/quote]You're using a method that is asking for a jpeg to reference from and you're giving it a .php file to reference. Link to comment https://forums.phpfreaks.com/topic/33434-solved-image-from-mysql-gd-problem/#findComment-156523 Share on other sites More sharing options...
Hyaku_ Posted January 9, 2007 Author Share Posted January 9, 2007 yeah, but img.php has:[code]Header("Content-Type: $type");[/code]in it. I thought it would do the trick..ok, the only way now that comes into my mind is to read the image from mysql and save it into tmp directory and then open it thru gd.. if anyone knows any other way, let me know! Thanks! Link to comment https://forums.phpfreaks.com/topic/33434-solved-image-from-mysql-gd-problem/#findComment-156524 Share on other sites More sharing options...
magic2goodil Posted January 9, 2007 Share Posted January 9, 2007 actually the problem may lie in the fact that u put in $_SERVER['DOCUMENT_ROOT']the file itself when being referenced most likely is not being referenced as /home/yoursite/public_html or however your site sees $_SERVER['DOCUMENT_ROOT'] if i call $_SERVER['DOCUMENT_ROOT'] . "index.php" on my site it will return http://www.collegebookx.com/home/collegeb/public_html/index.php when i reality that will not worktry it without the $_SERVER['DOCUMENT_ROOT'] and maybe try just img.php or ../img.php Link to comment https://forums.phpfreaks.com/topic/33434-solved-image-from-mysql-gd-problem/#findComment-156528 Share on other sites More sharing options...
Hyaku_ Posted January 9, 2007 Author Share Posted January 9, 2007 Thanks!Then the error would be probably about "file not found" or something.. anyway I tried, but unfortunetly that didn't work, so I thought if imagecreatefromjpeg checks for file extension, I could pass query:[code]img.php?some.jpg[/code]but it looks like it doesn't understand how to handle queries.. If it checks file type just by extension, not the actual header, I could rename my img.php to img.jpg and add another file type for php to execute.[code]AddType application/x-httpd-php .jpg[/code]I wonder if that would work.. :-X Link to comment https://forums.phpfreaks.com/topic/33434-solved-image-from-mysql-gd-problem/#findComment-156535 Share on other sites More sharing options...
magic2goodil Posted January 9, 2007 Share Posted January 9, 2007 Good luck man.Although if you have that problem and go to use your code online..how ill u fix it without apache or php.ini access? Link to comment https://forums.phpfreaks.com/topic/33434-solved-image-from-mysql-gd-problem/#findComment-156540 Share on other sites More sharing options...
Hyaku_ Posted January 9, 2007 Author Share Posted January 9, 2007 ok, now all the files that end with extention *.jpeg are executed as PHP source files, so I renamed my img.php script to img.jpeg, executed it, and it worked, but when I try to:[code]$img = imagecreatefromjpeg("img.jpeg");[/code]still the same error.. guess it checks the file type by some other way :-\Thanks! I have my own server and I use SSH to access it. Link to comment https://forums.phpfreaks.com/topic/33434-solved-image-from-mysql-gd-problem/#findComment-156542 Share on other sites More sharing options...
Accipiter Posted January 9, 2007 Share Posted January 9, 2007 Okay, I am fairly new to this too.But isn't the function you are looking for:[url=http://se.php.net/imagecreatefromstring]http://se.php.net/imagecreatefromstring[/url][code]$query = "SELECT IMG, IMG_TYPE FROM USER_ACCOUNT WHERE ID = 1";$query_exec = mysql_query($query);list($img, $type) = mysql_fetch_array($query_exec);$image = imagecreatefromstring($img);[/code]Then $image will be the resource which you can do a thumbnail with.Hope it works :) Link to comment https://forums.phpfreaks.com/topic/33434-solved-image-from-mysql-gd-problem/#findComment-156610 Share on other sites More sharing options...
Hyaku_ Posted January 9, 2007 Author Share Posted January 9, 2007 Thanks alot man!Thats exactly what I need!! ;) Link to comment https://forums.phpfreaks.com/topic/33434-solved-image-from-mysql-gd-problem/#findComment-156662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.