?
Solved

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

Posted on 2011-09-26
7
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

718 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