Solved

possible to read img properties and assign variable to the title?

Posted on 2011-09-26
7
281 Views
Last Modified: 2012-05-12
I was wondering if it is possible to read IMG properties and assign the title to a variable that I can use. I am not sure where to start with this. I went to php.net and found this exif_read_data() but couldn't determine if that is what I should be using for this.
any help would be great even a link to the right php function I should be trying to use.
0
Comment
Question by:jaxbrian
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:neorush
ID: 36600740
Are you trying to read the properties of an <img /> tag?  e.g. <img src="myimage.jpg" title="test"> or are you trying to read the properties of an image file?  e.g. http://www.example.com/myimage.jpg?  What information are you trying to get?
0
 
LVL 2

Author Comment

by:jaxbrian
ID: 36600772
sorry I wasn't clear on that. I am trying to read the title in the img properties itself  /folder/picture.jpg

I am using a readdir now to get all the images from a folder but I want to get the title of each image as well so can echo them into the <img src="folder/picture.jpg" title="<php echo $title; ?>">


thanks
0
 
LVL 6

Expert Comment

by:neorush
ID: 36600914
Some tags are / are not available depending on the image and how it was saved.  e.g. photoshops "save for web and devices" strips most exif data.  But here is how you would access that information.  Your server would also have to have php's exif extensions installed.
<?php
function getExifTitle($image){
	echo "Examing ".$image."<br />\n";
	$exif = exif_read_data($image, 'IFD0');
	if($exif===false){
		echo "No header data found.<br />\n";
		return false;
	}
	else echo "Image contains headers<br />\n";

	$exif = exif_read_data($image, 0, true);
	foreach ($exif as $key => $section) {
		foreach ($section as $name => $val) {
			echo "$key.$name: $val<br />\n";
		}
	}
	return $exif;
}
$exif_data = getExifTitle('folder/picture.jpg');
?>

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:jaxbrian
ID: 36601025
so I filled out all the information in the properties to see what it would retrieve. I would like to be able to set this which is one of the returned values "IFD0.ImageDescription: TEST to see"
to a variable, but I only want the value and in this case it would be "TEST to see"

0
 
LVL 6

Expert Comment

by:neorush
ID: 36601081
if the field ImageDescription is not present in the image, you will get no output.  Other wise you will get the contents of the field.  
<?php
function getExifTitle($image){
	$exif = exif_read_data($image, 'IFD0');
	if($exif) $exif = exif_read_data($image, 0, true);
	if(isset($exif['IFD0']['ImageDescription'])) return $exif['IFD0']['ImageDescription'];
	else return false;
}
echo getExifTitle('picture.jpg');
?>

Open in new window

0
 
LVL 6

Accepted Solution

by:
neorush earned 500 total points
ID: 36601094
Sorry, missed a return so there are no possible errors.
<?php
function getExifTitle($image){
	$exif = exif_read_data($image, 'IFD0');
	if($exif) $exif = exif_read_data($image, 0, true);
	else return false;
	if(isset($exif['IFD0']['ImageDescription'])) return $exif['IFD0']['ImageDescription'];
	else return false;
}
echo getExifTitle('picture.jpg');
?>

Open in new window

0
 
LVL 2

Author Closing Comment

by:jaxbrian
ID: 36602599
thank you very much. i am going to read more about the exif_read_data()
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Permalink issue in Wordpress archive 1 33
Keep getting 503 on Curl request 6 32
Session timeout 5 14
geting geocode of a user with using Google maps api 8 18
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now