Page 1 of 1
image hosting help
Posted: Sat Aug 08, 2009 10:56 pm
by Rev0
Ok so Ive written a script that creates an image based on info from the url. I want people to be able to type something like this into a fourm and for my script to return an image.
Code: Select all
[img]http://127.0.0.1/Main.php?u=463654&tc=225000225&bc=100225100[/\img]
Do I need to actully host the image on the server or can I just return the image?
If so how do I go about this because when I try:
all I get is an encoded string like this:
Code: Select all
??.$8?j??? V????j??Cs&zg?}*?k????=WQv?[? ?t ??|????>???9??K?z?8bU?????R?t?H??n?X?`(???I>?gk???,K?x??u-M?W?Q?w_ufMWSeQ?"?B???K?I.??p?9??????I?x?;h?
Instead of an actual image.
Re: image hosting help
Posted: Sun Aug 09, 2009 2:13 am
by cpetercarter
Have you tried to save the image to a file instead of outputting it direct?
Re: image hosting help
Posted: Sun Aug 09, 2009 6:04 am
by Rev0
Yes. Ive been able to edit the image and save it to the HDD.
Re: image hosting help
Posted: Sun Aug 09, 2009 10:37 am
by McInfo
Do you have a Content-Type header in your script?
Code: Select all
header('Content-Type: image/jpeg');
If that doesn't help, please post your script so we can better understand what is happening.
Edit: This post was recovered from search engine cache.
Re: image hosting help
Posted: Sun Aug 09, 2009 2:45 pm
by Rev0
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
K, I simplified it a little by taking some of the repetitive code out.
[EDIT] ive commented the code a little better so its easier to understand
Code: Select all
Function GenerateIMG($ml,$c,$ini_array)
{
$path = "C:\\Users\\Administrator\\Pictures\\sig.jpeg";
if (!file_exists($path)) {
echo 'File does not exist.';
} else {
$im = imagecreatefromjpeg($path);
if (!headers_sent()) {
header('Content-type: image/jpeg');
imagejpeg($im);
}
}
imagedestroy($im);
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Re: image hosting help
Posted: Tue Aug 11, 2009 10:21 am
by McInfo
Remove the call to header() from line 10. As it is now, if your script outputs error messages, they will be included in the body of the image. This will cause the browser to display garbage.
Replace line 60 with
Code: Select all
if (!headers_sent()) {
header('Content-Type: image/jpeg');
imagejpeg($im);
}
If everything works perfectly, you will see the image. If there are errors, you will see the errors instead of the image.
Edit: This post was recovered from search engine cache.
Re: image hosting help
Posted: Tue Aug 11, 2009 1:45 pm
by Rev0
Thanks for the input McInfo but its still not working :/
For debugging purposes Ive narrowed my code down to this to exclude anything that might be complicating the output, but its still spitting out jibberish.
Code: Select all
<?php
$im = @imagecreatefromjpeg("C:\\Users\\Admin\\Pictures\\sig.jpeg");
if($im)
{
If (!headers_sent()) {
header('Content-type: image/jpeg');
imageJPEG($im);
imageJPEG($im,"Saved.jpeg");
}
}
?>
Could someone run this script on their comp for me and see if it works? Im thinking its my computer because this shouldnt be so complicated.
Re: image hosting help
Posted: Tue Aug 11, 2009 2:16 pm
by McInfo
The script worked for me.
The error suppression operator (@) does not help when debugging.
Try this.
Code: Select all
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', true);
$path = "C:\\Users\\Admin\\Pictures\\sig.jpeg";
if (!file_exists($path)) {
echo 'File does not exist.';
} else {
$im = imagecreatefromjpeg($path);
if (is_resource($im) && !headers_sent()) {
header('Content-type: image/jpeg');
imagejpeg($im);
}
}
?>
Edit: This post was recovered from search engine cache.