Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts


PHP iptcembed Gallery3 to Flickr

A journey of sharing photo only got me into having a website of my own. When digital camera came out with decent mega pixel was an early adapter of the same. But soon realized sharing Pictures on email was not an option and  hosted pictures  on Tripod. Oh! they used to give 10MB of free hosting :) now Flicker gives one 1TB free. So long  story small after the managing own gallyery app writen initally with csv and php , later mysql and php and lastly Gallery for almost 10 years. found gallery development is kind of not that active it used to be. So thought of moving into Flickr which was big no in-between as they had restriction on free accounts. But now those restriction gone managing 7000+ picture and importing them with proper details remained a BIG challenage. At last came up with iptcembed  where all the details where written into  JPEG file itself and imported those image as set to Flickr.And all your details, tag, captions are set properly.

Here is how I did it

1. Copy Gallery's items table to temp table so we do not mess with live data
2. Add a new column to the temp table
ALTER TABLE `Yours_G3_items-new` ADD `album_name` TEXT NOT NULL
3. Find out the parent album id of each items and add that data in the new column.
UPDATE Yours_G3_items-new,Yours_G3_items  SET Yours_G3_items-new.album_name = Yours_G3_items.title WHERE Yours_G3_items-new.parent_id =
4. Export the new table with "|" as separator and "" as enclosed.

Now the PHP script
//File to be opened
$gallery_album_base = ..../gallery3/var/albums";
$new_gallery_album_base = <new location>/albums" ;
$handle = fopen($file, 'r') or die ("Fail to open input file \n\r") ;
$ln= 0 ;
// Some Functions Start
function csv_explode($delim='|', $str, $enclose='"', $preserve=false){
$resArr = array();
$n = 0;
$expEncArr = explode($enclose, $str);
foreach($expEncArr as $EncItem){
array_push($resArr, array_pop($resArr) . ($preserve?$enclose:'') . $EncItem.($preserve?$enclose:''));
$expDelArr = explode($delim, $EncItem);
array_push($resArr, array_pop($resArr) . array_shift($expDelArr));
$resArr = array_merge($resArr, $expDelArr);
return $resArr;

// iptc_make_tag() function by Thies C. Arntzen
function iptc_make_tag($rec, $data, $value)
$length = strlen($value);
$retval = chr(0x1C) . chr($rec) . chr($data);
if($length < 0x8000)
$retval .= chr($length >> 8) . chr($length & 0xFF);
$retval .= chr(0x80) .
chr(0x04) .
chr(($length >> 24) & 0xFF) .
chr(($length >> 16) & 0xFF) .
chr(($length >> 8) & 0xFF) .
chr($length & 0xFF);
return $retval . $value;
// Some Functions End
while ($line = fgets ($handle)){
$line = str_ireplace("\x0D", "", $line);
$line = urldecode ($line);
print ("just line : $ln \n");
if ($line===FALSE) print ("FALSE\n");
else {
//print ("I am $ln \n");
//print ($line) ;
$variables = csv_explode ("|", $line);
//print_r ($variables);
//26(album or photo) 25(title), 13(image_path), 4(details),33(album_name/tag)

if ( $variables[26] == photo ){
//Path new and old path
$old_path = $gallery_album_base . '/' . $variables[13];
$image_name_new = $new_gallery_album_base . '/' . $variables[13];
$path_parts = pathinfo ($image_name_new);
if (!file_exists($path_parts['dirname'])) {
print ("makeing directory {$path_parts['dirname']} \n") ;
mkdir ($path_parts['dirname'], 0777,true);

// Set the IPTC tags
$iptc = array(
'2#120' => "$variables[4]",
'2#105' => "$variables[25]",
'2#005' => "$variables[25]",
'2#015' => "$variables[33]",
'2#116' => 'Copyright, www santm com'
// Convert the IPTC tags into binary code
$data = '';
foreach($iptc as $tag => $string)
$tag = substr($tag, 2);
$data .= iptc_make_tag(2, $tag, $string);
// Embed the IPTC data
$content = iptcembed($data, $old_path);
// Write the new image data out to the file.
$fp = fopen($image_name_new, "wb");
fwrite($fp, $content);
print ("working on $image_name_new \n");
//$size = getimagesize($image_name_new, $info);
// $iptc = iptcparse($info['APP13']);
// var_dump($iptc);
} //end of if photo loop
} // end of else loop
} // end of while loop
# Close the File.
I Wish there was API where I could import the image from my old hosting company to Flickr directly instead of uploading them via their PC up-loader.

More here on major phpfunction


Gallerry 3 sneak peak

Gallery 3 is going to a big change from current gallery 2 and initial alpha release did not have any migration path from gallery2. It was pushed to Beta release after 2 alpha releases. but to my surprise I found it was implemented in alpha 4 and here is the test result of a new neat code. I am really liking the new compact code making gallery 3 faster and lean compared to its predecessor. Similar, to WordPress new theme development is easy no more smarty - thank God I never really mastered those PERL look alike. Now it is simple PHP and CSS. Another core feature is Akismet which does a fantastic job of filtering spam comments. I was able to import 3000+ images in 200+ albums without any problem. There are few things which needs to be ironed before I can put the same in production.


create typewriter effect with ming php for flash (swf) movie

This is nice and simple code it creates the simple effect which you might have seen in lots of web sites. As it is PHP you can use the same from your own news reader to database.

setBackground(0x00,0x00,0x00);// SM - This is very important as it set sets the speed of the movie// SM - Higher the number faster the typing will appear$movie->setRate(3);// SM - This one will depends upon you$movie->setDimension(600,40);$movie->setFrames(31);$movie->nextFrame();// Define your String here $str = 'Miing Typewriter Effect'; /* SM - As you note The space between character if not fixed SM - due to font width so you have to figure out your own SM - Now we split our string and make an array with the same */ $chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);// print_r($chars);$inc = 0 ;for($i=0;$isetFont($myFont); $myText->setColor(255,255,255); $myText->SetHeight(30); $myText->addString($chars[$i]); echo ("$chars[$i] \n") ; $firstText=$movie->add($myText); $firstText->moveTo($inc,30); $inc = $inc + 18; // SM - this is very critical as you need to add this extra frame to make this effect of some typewriter $movie->nextframe(); // SM - This helps to determine the width of the movie // SM - turn only if you need the same // echo "inc is $inc \n" ; } // SM - we do not want to loop this movie// $movie->add(new SWFAction("stop();")); // SM - Save the movie $movie->save("/tmp/banner.swf",9);?>

Day 3 - Rishikesh

The weather looked gloomy with an overcast sky as we woke up. We had breakfast at the hotel and decided to visit Rishikesh today. Again we...