d.shankar Posted January 22, 2008 Share Posted January 22, 2008 I have this code that displays an image using GD library. Here is the code <?php echo "<img src=".crImage()." alt='newimage'>"; function crImage() { header("Content-type: image/gif"); $im = imagecreatefromgif("new.gif"); imagegif($im); imagedestroy($im); } ?> The image gets loaded but The alt text 'newimage' is not appearing.. Is it possible to do it ? Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/ Share on other sites More sharing options...
asmith Posted January 22, 2008 Share Posted January 22, 2008 hmm in what browser you are testing it ? try to put title='newimage' and see what happens. i think firefox do not show alt as a title bar . which IE shows alt as a title bar if there is no title for the img tag has been set. so if you are using other browsers but IE, they should show the image or instead of showing image they show alt . so i guess you have to put title="newimage" for all browsers. hope this is what you wanted. Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-445871 Share on other sites More sharing options...
d.shankar Posted January 22, 2008 Author Share Posted January 22, 2008 No smith it doesn't work... Does gd has any function to do this ? Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-445881 Share on other sites More sharing options...
asmith Posted January 22, 2008 Share Posted January 22, 2008 ok , found your problem : when there is no src address (not important that it is valid or not) , then the title won't work , look at these examples : echo "<img src=".crImage()." title='newimage' />"; echo "<img src=11".crImage()." title='newimage' />"; the first do not show , but the second line shows the title . solution : (the first solution that came to my mind, maybe you can dig better) save your image lines in another file , save that file like "image.php" . then : <img src="image.php" title=newimage /> Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-445893 Share on other sites More sharing options...
d.shankar Posted January 22, 2008 Author Share Posted January 22, 2008 Smith there must be someother problem i think.. It is not working. Btw. did you try it ?? Same problem still. This is my file image.php <?php echo "<img src=11".crImage()." title='newimage'>"; function crImage() { header("Content-type: image/png"); $im = imagecreatefrompng("untitled1.PNG"); imagepng($im); imagedestroy($im); } ?> I tried viewing source its just blank. You got any idea ? Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-445898 Share on other sites More sharing options...
Barand Posted January 22, 2008 Share Posted January 22, 2008 image.php <?php header("Content-type: image/png"); $im = imagecreatefrompng("untitled1.PNG"); imagepng($im); imagedestroy($im); ?> in another php file <?php echo '<img src="image.php" alt="newimage" title="newimage">'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-445917 Share on other sites More sharing options...
asmith Posted January 22, 2008 Share Posted January 22, 2008 barand said it more clear, that was the thing i was trying to tell you. Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-445928 Share on other sites More sharing options...
d.shankar Posted January 22, 2008 Author Share Posted January 22, 2008 I get it but that is not the requirement. It is possible to set the alt or title attrib in image.php itself ? Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-445955 Share on other sites More sharing options...
asmith Posted January 22, 2008 Share Posted January 22, 2008 first : image.php is a php file . alt and attrib is for HTML tags. so you can't set a HTML language element for a php language . so the only way is put image.php in the src of a img tag , then add atrib to it . second : why you post always in quotes ? Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-445978 Share on other sites More sharing options...
d.shankar Posted January 22, 2008 Author Share Posted January 22, 2008 Actually i will be giving this code to my different users ... these users dont have PHP installed so they have access it from my server. they have to include like this <html> <body> <img src='http://www.example.com/img.php'> </body> </html. As you said the img.php will now call image.php ... but it does not work in the client side. If i access http://www.example.com/img.php directly then it works .. by putting it inside an image tag it fails to do so. Quote makes posts looks cuter that why i do. Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-445989 Share on other sites More sharing options...
asmith Posted January 22, 2008 Share Posted January 22, 2008 your users get that image.php right . they don't need to have php installed. when they go to www.example.com/image.php , YOUR php engine will make that for them . so nothing to worry about . Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-445996 Share on other sites More sharing options...
d.shankar Posted January 22, 2008 Author Share Posted January 22, 2008 No dude.. they have to add it as an image to their site ... got it ?? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-445998 Share on other sites More sharing options...
asmith Posted January 22, 2008 Share Posted January 22, 2008 from what i know , any url that cmes from YOUR site , HAVE TO be interpret by your site php interpreter, then it will have premission to go anywhere. so when a user puts "http://www.yoursite.com/image.php" in HIS site like : USER'S SITE HTML ONly PAGE : <img src="http://www.yoursite.com/image.php" alt="haha! got your picture!" /> he will use YOUR php interpreter to show the picture . when you do this, the fonts get smaller ! so poor readers !!! Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446002 Share on other sites More sharing options...
d.shankar Posted January 22, 2008 Author Share Posted January 22, 2008 Yeah thats what i am saying bud.. It wont work. I tried this already.. index.html in client side <html> <body> <img src='http://www.example.com/img.php?id=1'> </body> </html> img.php @ example.com <?php $id=$_GET['id']; if($id==1) { echo '<img src="image.php" alt="newimageloaded" title="newimageloaded">'; } if($id==0) { echo '<img src="noimage.php" alt="noimageloaded" title="noimageloaded">'; } ?> image.php @ example.com <?php header("Content-type: image/png"); $im = imagecreatefrompng("validimage.PNG"); imagepng($im); imagedestroy($im); ?> noimage.php @ example.com <?php header("Content-type: image/png"); $im = imagecreatefrompng("blankimage.PNG"); imagepng($im); imagedestroy($im); ?> This is my requirement. Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446009 Share on other sites More sharing options...
asmith Posted January 22, 2008 Share Posted January 22, 2008 what is not working ? client can't view image ?? this is the thing that is not working ? Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446013 Share on other sites More sharing options...
d.shankar Posted January 22, 2008 Author Share Posted January 22, 2008 Yeah client cant view image. ! If i give this code to the client then he can view <html> <body> <img src='http://www.example.com/image.php'> </body> </html> But i need to achieve using the former method. Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446018 Share on other sites More sharing options...
asmith Posted January 22, 2008 Share Posted January 22, 2008 i see , src on the img tag only need an image , it won't accept a page that the result is an image , it is your problem . let's try this : do not redirect in the img.php example, do all the work in the image.php . like : image.php @ example.com <?php header("Content-type: image/png"); if($id==1) { $imageToSet = "validimage.PNG"; } elseif($id==0) { $imageToSet = "blankimage.PNG"; } $im = imagecreatefrompng($imageToSet); imagepng($im); imagedestroy($im); ?> so now the client will put this : <img src='http://www.example.com/image.php?id=1'> Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446021 Share on other sites More sharing options...
d.shankar Posted January 22, 2008 Author Share Posted January 22, 2008 Yeah you are 99.9% arrived to the solution buddy. But i need to display different alt or title attribute to that image. The values 1 & 0 will be dynamically changing.. So in this case both the images will have the same alt or title text that is passed from the client side. What i am saying is that , if the alt or title text is be passed from the server side then the problem will be over. Can it be done ? Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446023 Share on other sites More sharing options...
asmith Posted January 22, 2008 Share Posted January 22, 2008 well i'm not a pro . but i guess you can do some tricks! this is the first thing that came to my mind : maybe later ,better thing come : create the img tag with alt and title on YOUR site in a html file , like : <div><img src='http://www.example.com/image.php?id=1' alt=image></div> then make your client side html somehow that it get the line from your html , and paste it to his. one of the ways could be : use frames . client side page use a frame , and in the frame you put YOUR site html . get it ? jus ttry to think of ways , which you could get that div part from your site and paste it to his page . ps : anyway do a title worth this much trouble ? Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446029 Share on other sites More sharing options...
d.shankar Posted January 22, 2008 Author Share Posted January 22, 2008 Dude you are awesome...... thanks for helping a lot. But alt attribute is very critical in my aspect... may be i should forget it i think. :'( Thanks again smith. :) Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446033 Share on other sites More sharing options...
asmith Posted January 22, 2008 Share Posted January 22, 2008 don't give up this much soon , if this is what you want , go till you nail it down ! goto the phpfreaks HTML forum , or other good HTML forums you know , and start a thread , how can i copy a div or something and its contents from a page into another page? i'm sure you'll find it . (bad solution : why don't you choose a title that have a meaning to any image ? i mean lol , for example you have 2 images , one is a dog and one is a cat . the title can be for dog : "dog" , and for cat : "cat" . now instead of it you can change the title to "animal" or " cat & dog" that can apply to both ) Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446038 Share on other sites More sharing options...
d.shankar Posted January 22, 2008 Author Share Posted January 22, 2008 Ok buddy i will give it a try... Btw is this possible.. will this incur a heavy load to server ? <html> <body> <img src='http://www.example.com/image.php?id=1' alt='http://www.example.com/status.php?id=1' > </body> </html> You already know what's there in image.php so i am not pasting the code. status.php <?php if($id==1) { $result = "Image Valid"; } if($id==0) { $result = "Image Blank"; } echo $result; ?> Will this fetch the image and alt attrib ?? Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446043 Share on other sites More sharing options...
asmith Posted January 22, 2008 Share Posted January 22, 2008 no , it won't work , the alt would show the url you typed . what this alt exactly says , maybe we could solve it in other way. is it some kind of explanation ? what do you have in mind for alt or title ? Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446047 Share on other sites More sharing options...
d.shankar Posted January 22, 2008 Author Share Posted January 22, 2008 Dude its really driving us too mad.. I will try to with your div suggestion instead. Btw i congragulate on your 500th post soon Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446051 Share on other sites More sharing options...
Barand Posted January 22, 2008 Share Posted January 22, 2008 Why are you creating a GD image which just loads another image then outputs it. You might as well just put <img src="validimage.PNG"> in the html file Quote Link to comment https://forums.phpfreaks.com/topic/87172-gd-help/#findComment-446334 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.