Solved

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

Posted on 2011-09-26
7
292 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How has this flight information been added to this website? 7 33
How to fix Datetime in MySQL? 4 51
parse url to form? 7 26
$_SERVER Variable question 31 31
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 dynamically set the form action using jQuery.

821 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