Solved

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

Posted on 2011-09-26
7
307 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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

624 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