Solved

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

Posted on 2011-09-26
7
276 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 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

13 Experts available now in Live!

Get 1:1 Help Now