muckv Posted November 10, 2008 Share Posted November 10, 2008 hey, when I call the method get_copyright() the array $meta becomes null instead op returning the value of $meta['copyright'] Everything goes well in the constructor, but when that method is called (see above) does anybody see what I did wrong <?php class IPTC{ var $meta; var $image; function __construct($image){ $meta=array(); $this->meta=$meta; $this->image=$image; $meta = array( 'credit' => '', 'caption' => '', 'created_timestamp' => 0, 'copyright' => '', 'title' => '', ); $size=getimagesize($image,$info); if ( isset ($info['APP13'])) { $iptc=iptcparse($info['APP13']); if ( !empty($iptc['2#110'][0]) ) $meta['credit'] = utf8_encode(trim($iptc['2#110'][0])); elseif ( !empty($iptc['2#080'][0]) ) $meta['credit'] = utf8_encode(trim($iptc['2#080'][0])); if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]); if ( !empty($iptc['2#120'][0]) ) // caption $meta['caption'] = utf8_encode(trim($iptc['2#120'][0])); if ( !empty($iptc['2#116'][0]) ) // copyright $meta['copyright'] = utf8_encode(trim($iptc['2#116'][0])); if ( !empty($iptc['2#005'][0]) ) // title $meta['title'] = utf8_encode(trim($iptc['2#005'][0])); } } function get_credit(){ return $meta['credit']; } function get_timestamp(){ return $meta['created_timestamp']; } function get_caption(){ return $meta['caption']; } function get_copyright(){ return $meta['copyright']; } function get_title(){ return $meta['title']; } } $image_info = new IPTC('suzy1.jpg') or die ('kan geen iptc gegevens extracten uit image'); echo $image_info->get_copyright()or die('geen copyright beschikbaar'); Quote Link to comment Share on other sites More sharing options...
ranjuvs Posted November 10, 2008 Share Posted November 10, 2008 Try this <?php <?php class IPTC{ var $meta; var $image; function __construct($image){ $this->image=$image; $this->meta = array( 'credit' => '', 'caption' => '', 'created_timestamp' => 0, 'copyright' => '', 'title' => '', ); $size=getimagesize($image,$info); if ( isset ($info['APP13'])) { $iptc=iptcparse($info['APP13']); if ( !empty($iptc['2#110'][0]) ) $this->meta['credit'] = utf8_encode(trim($iptc['2#110'][0])); elseif ( !empty($iptc['2#080'][0]) ) $this->meta['credit'] = utf8_encode(trim($iptc['2#080'][0])); if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) $this->meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]); if ( !empty($iptc['2#120'][0]) ) // caption $this->meta['caption'] = utf8_encode(trim($iptc['2#120'][0])); if ( !empty($iptc['2#116'][0]) ) // copyright $this->meta['copyright'] = utf8_encode(trim($iptc['2#116'][0])); if ( !empty($iptc['2#005'][0]) ) // title $this->meta['title'] = utf8_encode(trim($iptc['2#005'][0])); } } function get_credit(){ return $this->meta['credit']; } function get_timestamp(){ return $this->meta['created_timestamp']; } function get_caption(){ return $this->meta['caption']; } function get_copyright(){ return $this->meta['copyright']; } function get_title(){ return $this->meta['title']; } } $image_info = new IPTC('ARPC.JPG') or die ('kan geen iptc gegevens extracten uit image'); $res = $image_info->get_copyright()or die('geen copyright beschikbaar'); echo $res; Quote Link to comment Share on other sites More sharing options...
muckv Posted November 10, 2008 Author Share Posted November 10, 2008 nope, same result Quote Link to comment Share on other sites More sharing options...
bobbinsbro Posted November 10, 2008 Share Posted November 10, 2008 the array $info doesn't exist, so isset ($info['APP13']) returns false, so the if block isn't executed, so $meta['copyright'] isn't created/populated in the constructor. Quote Link to comment Share on other sites More sharing options...
muckv Posted November 10, 2008 Author Share Posted November 10, 2008 Well, Still the same problem, the if structure does get executed cause I follow it while debugging I can see the correct value in meta['copyright'] until the method gets called <?php class IPTC{ var $meta; var $info; function __construct($image){ $this->image=$image; $this->meta=array( 'credit' => '', 'caption' => '', 'created_timestamp' => 0, 'copyright' => '', 'title' => '', ); $size=getimagesize($image,$info); $this->info=$info; if ( isset ($info['APP13'])) { $iptc=iptcparse($info['APP13']); if ( !empty($iptc['2#110'][0]) ) $meta['credit'] = utf8_encode(trim($iptc['2#110'][0])); elseif ( !empty($iptc['2#080'][0]) ) $meta['credit'] = utf8_encode(trim($iptc['2#080'][0])); if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]); if ( !empty($iptc['2#120'][0]) ) // caption $meta['caption'] = utf8_encode(trim($iptc['2#120'][0])); if ( !empty($iptc['2#116'][0]) ) // copyright $meta['copyright'] = utf8_encode(trim($iptc['2#116'][0])); if ( !empty($iptc['2#005'][0]) ) // title $meta['title'] = utf8_encode(trim($iptc['2#005'][0])); } } function get_credit(){ return $meta['credit']; } function get_timestamp(){ return $nfo['created_timestamp']; } function get_caption(){ return $meta['caption']; } function get_copyright(){ return $meta['copyright']; } function get_title(){ return $meta['title']; } } $image_info = new IPTC('suzy1.jpg') or die ('kan geen iptc gegevens extracten uit image'); echo $image_info->get_copyright(); ?> Quote Link to comment Share on other sites More sharing options...
bobbinsbro Posted November 10, 2008 Share Posted November 10, 2008 well, i just ran the code you pasted (had to fix it to use $this), and i added this line: echo "in if"; on line 26, right after this: $iptc=iptcparse($info['APP13']); and the text "in if" does not display. as i said, $info['APP13'] does not get set/declared/initialized anywhere in the class, and so the if(isset($info['APP13'])) does not execute. Quote Link to comment Share on other sites More sharing options...
muckv Posted November 10, 2008 Author Share Posted November 10, 2008 I just ran this code and In if IS echoed, i'm really in the dark here <?php class IPTC{ var $meta; var $info; function __construct($image){ $this->image=$image; $this->meta=array( 'credit' => '', 'caption' => '', 'created_timestamp' => 0, 'copyright' => '', 'title' => '', ); $size=getimagesize($image,$info); $this->info=$info; if ( isset ($info['APP13'])) { echo "in if"; $iptc=iptcparse($info['APP13']); if ( !empty($iptc['2#110'][0]) ) $meta['credit'] = utf8_encode(trim($iptc['2#110'][0])); elseif ( !empty($iptc['2#080'][0]) ) $meta['credit'] = utf8_encode(trim($iptc['2#080'][0])); if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]); if ( !empty($iptc['2#120'][0]) ) // caption $meta['caption'] = utf8_encode(trim($iptc['2#120'][0])); if ( !empty($iptc['2#116'][0]) ) // copyright $meta['copyright'] = utf8_encode(trim($iptc['2#116'][0])); if ( !empty($iptc['2#005'][0]) ) // title $meta['title'] = utf8_encode(trim($iptc['2#005'][0])); } } function get_credit(){ return $meta['credit']; } function get_timestamp(){ return $meta['created_timestamp']; } function get_caption(){ return $meta['caption']; } function get_copyright(){ return $meta['copyright']; } function get_title(){ return $meta['title']; } } $image_info = new IPTC('suzy1.jpg') or die ('kan geen iptc gegevens extracten uit image'); echo $image_info->get_copyright(); Quote Link to comment Share on other sites More sharing options...
bobbinsbro Posted November 10, 2008 Share Posted November 10, 2008 well, i'm all out. it still doesn't work for me... :-\ what version of php are you running? Quote Link to comment Share on other sites More sharing options...
muckv Posted November 10, 2008 Author Share Posted November 10, 2008 5.2.6 Quote Link to comment Share on other sites More sharing options...
muckv Posted November 11, 2008 Author Share Posted November 11, 2008 anyone? Quote Link to comment Share on other sites More sharing options...
trq Posted November 11, 2008 Share Posted November 11, 2008 return $meta['copyright']; Needs to be.... return $this->meta['copyright']; for starters. All your methods need changing. Quote Link to comment Share on other sites More sharing options...
muckv Posted November 11, 2008 Author Share Posted November 11, 2008 thanks, still no output Quote Link to comment Share on other sites More sharing options...
muckv Posted November 11, 2008 Author Share Posted November 11, 2008 this is the content of image_info so you see the array $meta is empty but why? <?php class IPTC{ var $meta; var $info; function __construct($image){ $this->image=$image; $this->meta=array( 'credit' => '', 'caption' => '', 'created_timestamp' => 0, 'copyright' => '', 'title' => '', ); $size=getimagesize($image,$info); $this->info=$info; if ( isset ($info['APP13'])) { $iptc=iptcparse($info['APP13']); if ( !empty($iptc['2#110'][0]) ) $meta['credit'] = utf8_encode(trim($iptc['2#110'][0])); elseif ( !empty($iptc['2#080'][0]) ) $meta['credit'] = utf8_encode(trim($iptc['2#080'][0])); if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]); if ( !empty($iptc['2#120'][0]) ) // caption $meta['caption'] = utf8_encode(trim($iptc['2#120'][0])); if ( !empty($iptc['2#116'][0]) ) // copyright $meta['copyright'] = utf8_encode(trim($iptc['2#116'][0])); if ( !empty($iptc['2#005'][0]) ) // title $meta['title'] = utf8_encode(trim($iptc['2#005'][0])); } } function get_credit(){ return $this->meta['credit']; } function get_timestamp(){ return $this->meta['created_timestamp']; } function get_caption(){ return $this->meta['caption']; } function get_copyright(){ return $this->meta['copyright']; } function get_title(){ return $this->meta['title']; } } $image_info = new IPTC('suzy1.jpg') or die ('kan geen iptc gegevens extracten uit image'); echo $image_info->get_copyright(); Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 11, 2008 Share Posted November 11, 2008 You are setting the $this->meta variable in correctly. Here if ( !empty($iptc['2#110'][0]) ) $meta['credit'] = utf8_encode(trim($iptc['2#110'][0])); elseif ( !empty($iptc['2#080'][0]) ) $meta['credit'] = utf8_encode(trim($iptc['2#080'][0])); if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]); if ( !empty($iptc['2#120'][0]) ) // caption $meta['caption'] = utf8_encode(trim($iptc['2#120'][0])); if ( !empty($iptc['2#116'][0]) ) // copyright $meta['copyright'] = utf8_encode(trim($iptc['2#116'][0])); if ( !empty($iptc['2#005'][0]) ) // title $meta['title'] = utf8_encode(trim($iptc['2#005'][0])); } You're populating your $meta array. $this->meta and $meta are not the same. You'll need to change all instances of $meta to $this->meta or add the following line after the above block of code $this->meta = $meta; Quote Link to comment Share on other sites More sharing options...
muckv Posted November 12, 2008 Author Share Posted November 12, 2008 ******* A thanks man Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.