Jump to content

GD Help !


d.shankar

Recommended Posts

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 />

 

 

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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 ? :D

 

Link to comment
Share on other sites

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. ::)

Link to comment
Share on other sites

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 !!!

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'>

 

 

 

 

 

Link to comment
Share on other sites

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 ? :-[

Link to comment
Share on other sites

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 ? ;)

 

 

 

Link to comment
Share on other sites

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 :  ;D 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 ;)  )

Link to comment
Share on other sites

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 ??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.