Ubuntu Add-Ons with PHP

The family album has been growing and coping with the volume of images, stored under Ubuntu is becoming a problem. With the attitude – “waste time to save time” – started exploring the options for some kind of digital workflow to automate whatever I can or at least keep mouse clicks to a minimum.

One particular problem is adding comments to images; most archiving software (like gthumb) has you store stuff seperately from the images, maintaining their own databases (in the case of gthumb, under ~/.gnome2/gthumb). But I’d rather have comments stay with the image (e.g. using Exif – there are other ways but Exif wins on being widely supported).

Scripting Nautilus

By chance ran into g-scripts and the notion that you can extend Nautilus (the Ubuntu file manager GUI) with your own scripts. In fact there’s a short tutorial here. The examples on g-scripts use bash scripts but figured this was a good opportunity to mis-use PHP.

Zenity

In addition to extending Nautilus, also took advantage of Zenity (I’m running Ubuntu as in Gnome, not Kbuntu), which allows you to pop dialogs out of shell scripts. For example if you run $ zenity --question --text "Feeling OK?", up pops a dialog like…

Ubuntu Add-Ons with PHP

There’s more on Zenity here. In fact it is a bad idea to use PHP for this given that Perl has this nailed with UI::Dialog, which supports multiple backends including Zenity and KDialog (meaning your scripts could then also work under Kbuntu) but for fun will continue with PHP here.

Tips

Anyway – some quick tips (which is pretty much covered in above tutorials) then the code.

  • You store you scripts under ~/.gnome2/nautilus-scripts
  • Make sure you’ve got the php5-cli package installed ($ sudo apt-get install php5-cli)
  • You need to add the PHP shebang line at the top of your script (I omitted the .php extension) e.g. #!/usr/bin/php
  • Make sure you make them executable ($ chmod +x ~/.gnome2/nautilus-scripts/myscript)
  • To activate the scripts, you need to point Nautilus at the scripts directory (menu: Go > Location). You may need to reload if you create additional scripts
  • To run the scripts, right click on a file and select the scripts menu

Exif Manipulation

Anyway – succeeded in throwing together two scripts, one to view Exif comments (for which it was easiest just to use the exif_read_data() function) in a Zenity info dialog and another to edit comments using a Zenity text entry dialog. For the second I used Martin Geisler’s excellent PEL library, which has an example that I could pretty much copy and paste, replacing the command line interface with Zenity (side note: PEL 0.9 isn’t quite stable it seems – if you get error messages about redefining constants, edit the script and comment the second constant assignment). So now right clicking on an image and selecting my exif_comment_edit script I get a dialog like…

Ubuntu Add-Ons with PHP

The code…

exif_view_comment

  #!/usr/bin/php <?php function ohDearMe($msg) {     `zenity --error --text="$msg" --title="Exif Info Error"`;     exit(1); }  if ( !isset($argv[1]) ) {     ohDearMe("Image filename required");     exit(1); }  $file = getcwd().'/'.$argv[1];  if (!is_readable($file)) {   ohDearMe(sprintf("Unable to read: %s", $file));   exit(1); }  $title = 'Exif Info for '.addslashes(basename($file));  $data = exif_read_data($file);  if ( !$data ) {     ohDearMe('Unrecognized image format!'); }  if ( !isset($data['ImageDescription']) || trim($data['ImageDescription']) == '' ) {     ohDearMe('Image contains no comment'); }  $out = $data['ImageDescription'];  `zenity --info --text="$out" --title="$title"`; 

exif_edit_comment

  #!/usr/bin/php <?php require_once('pel/PelDataWindow.php'); require_once('pel/PelJpeg.php'); require_once('pel/PelTiff.php');  function ohDearMe($msg) {     `zenity --error --text="$msg" --title="Exif Info Error"`;     exit(1); }  if ( !isset($argv[1]) ) {     ohDearMe("Image filename required");     exit(1); }  $in = getcwd().'/'.$argv[1];  if (!is_readable($in)) {   ohDearMe(sprintf("Unable to read: %s", $in));   exit(1); }  $title = 'Exif Info for '.addslashes(basename($in));  $data = new PelDataWindow(file_get_contents($in));  if (PelJpeg::isValid($data)) {          $jpeg = $file = new PelJpeg();     $jpeg->load($data);     $app1 = $jpeg->getSection(PelJpegMarker::APP1);          if ($app1 == null) {                  $app1 = new PelExif();         $jpeg->insertSection(PelJpegMarker::APP1, $app1, 2);         $tiff = new PelTiff();         $app1->setTiff($tiff);              } else {         $tiff = $app1->getTiff();     }  } elseif (PelTiff::isValid($data)) {      $tiff = $file = new PelTiff();     $tiff->load($data);    } else {          ohDearMe('Unrecognized image format!');      }  $ifd0 = $tiff->getIfd();  if ($ifd0 == null) {      $ifd0 = new PelIfd();     $tiff->setIfd($ifd0);      }  $desc = $ifd0->getEntry(PelTag::IMAGE_DESCRIPTION);  if ($desc == null) {          $description = exec(         'zenity --entry --title="Exif New Comment" --text="Enter comment" --width=800 2>&1'         );     $desc = new PelEntryAscii(PelTag::IMAGE_DESCRIPTION, $description);     $ifd0->addEntry($desc);    } else {          $entry_text = addslashes($desc->getValue());     $description = exec('zenity --entry --title="Exif Existing Comment" --entry-text="'.         $entry_text.'" --text="Enter comment" --width=800 2>&1');     $desc->setValue($description);      }  file_put_contents($in, $file->getBytes());  

It goes without saying but will say anyway – use at your own risk!

Replay

Category: programming Time: 2006-08-16 Views: 2
Tags:

Related post

  • Firefox for Ubuntu add-ons 2014-03-25

    I am considering to install Ubunta on my PC. Currently also have firefox for windows installed with a number of add-ons. Are those same add-ons available under Ubuntu? --------------Solutions------------- I use Ubuntu at work, OSX at home. I can use

  • Firefox add-ons with a rich look and feel 2009-07-24

    I am looking for examples of the "best looking" Firefox add-ons. By "best looking" I mean usable and stylish look and feel. I am not necessarily looking for "must have" add-ons but for examples of how rich an add-on can be. O

  • Developing EE add-ons with code assist 2014-01-17

    First off, pardon the noob aspect of this question. I have developed on other platforms, but it's been a while now. I was starting to build an EE2 module for one of my sites and I keep getting frustrated in needing to print_r() everything to see what

  • How to install APC on a vagrant box running Ubuntu 12.04 with PHP 5.4? 2013-01-11

    In my "Vagrant" file I have this line: chef.add_recipe("php::module_apc") But it gives me this error: [2013-01-11T22:14:53+00:00] INFO: Processing package[php-apc] action install (php::module_apc line 34) ==============================

  • How to add product in woocommerce with php code 2014-03-10

    I want to add products with PHP code like below: $post_information = array( 'post_title' => 'new item shop', 'post_content' => 'this is new item shop', 'post_type' => 'post', 'post_status' => 'publish' ); $post_id = wp_insert_post($post_inform

  • PHP 5.5 on Ubuntu with php-mcrypt: Unmet dependencies 2014-09-20

    I have an ubuntu server running with PHP 5.5 $ php -v PHP 5.5.3-1ubuntu2 (cli) (built: Oct 9 2013 14:49:12) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies with Zend OPcache v7.0.3-dev, Copyright (c

  • Add a column with PHP and HTML (MYSQLI) 2016-01-26

    I want to make a input type and if I fill in the text it must automatically go to my phpmyadmin. How can I add columns with php code? This is what I have so far: <!DOCTYPE html> <?php include 'connectie.php'; ?> <html> <head> <?

  • Is the common use of 'Add-ons' (on Firefox) recommended for terminal server installs? 2009-08-24

    Is the use of 'Add-ons' on Firefox safe (stable) and secure on a terminal server? The install of a few Firefox add-ons has been recently proposed to us for our Terminal Server users. Has anyone had experience with enabling some very user oriented add

  • How to run older add-ons in Firefox 3.6? 2010-02-27

    Is there any way to run older add-ons with the newer Firefox 3.6? If it were possible: is this a good idea, or should we wait for the original developer to release an update? Are there any cons to forcing an addon to run in newer versions of Firefox?

  • How can I make Firefox 4 Sync add-ons 2011-02-07

    As we know Firefox Sync add-on comes installed by default in new Firefox 4 Beta. This add-on allows to sync bookmarks, passwords, preferencies, histories, tabs, BUT not add-on. It would be perfect to see this feature also, because many of us use it.

  • Removing Firefox in Ubuntu with all add-ons like it never existed 2010-12-09

    I have been using firefox for a long time in Ubuntu, I downloaded some add-ons but it made firefox extremely slow, even if I remove them nothing will change. I tried to remove firfox also but re-installing it will somehow recover the same firefox I h

  • Installing Ubuntu with Unity but without the "Big Brother" add-ons and prebundled app cruft 2014-02-28

    I just tried the minimal Ubuntu install (a 36MB mini.iso) to see if I could get a normal Ubuntu desktop installation with Unity but without the unwanted cruft such as Amazon/Ebay/Music suggestions in search, and the LibreOffice suite, and many other

  • 8 Heroku Add-ons for Production Ready PHP Apps 2014-07-11

    This article was sponsored by Heroku, the cloud application platform. Thank you for supporting the sponsors that make SitePoint possible! Introduction Heroku is a cloud application platform that makes it super easy to deploy and maintain apps. They t

  • Disabling IE add-ons and toolbars with Group Policy? 2011-02-01

    I'd love to have the peace of mind of knowing that none of my desktops have toolbars, "browser helpers" or any other crap like that running. Has anybody done this successfully with Group Policy? I found this article, but it's not all that clear:

  • Installing Nginx with PHP and MariaDB (as MySQL replacement) - LEMP -on Ubuntu 15.10 (Wiley Werewolf) 2012-01-03

    Nginx (pronounced "engine x") is a free, open-source, high-performance HTTP server. Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption. This tutorial shows how you can install Nginx on an Ubunt

  • Installing Nginx With PHP 5.3 And PHP-FPM On Ubuntu Lucid Lynx (10.04) 2012-03-17

    Installing Nginx With PHP 5.3 And PHP-FPM On Ubuntu Lucid Lynx (10.04) Follow me on Twitter http://kjette.se/blog/2010/06/nginx-php-fpm-ubuntu-lucid-lynx/ In this post I will explain how to install Nginx with PHP 5.3.3 and PHP-FPM on Ubuntu Lucid Lyn

  • Installing Nginx With PHP 5.3 And PHP-FPM On Ubuntu Lucid Lynx (10.04) Without Compiling Anything 2012-10-27

    Installing Nginx With PHP 5.3 And PHP-FPM On Ubuntu Lucid Lynx (10.04) Without Compiling Anything Version 1.0 Follow me on Twitter Since Apache is most of the time a memory hungy process, people started to look for different ways to host their websit

  • Git subtree with add-ons that have a themes folder 2013-02-06

    I've taken to installing add-ons that I have in development in separate repositories as submodules into each of my EE projects. This has worked fine for add-ons that do not have a themes folder, but I am now finally in the situation where I want to d

  • Updating PHP on Ubuntu 12.04 with Parallels Plesk 2015-01-10

    I've tried a few times to update php on my server from version 5.3 to the latest 5.5 with: sudo add-apt-repository ppa:ondrej/php5 It seems to work fine but it also updates Apache which I think is modified for plesk and caused it to stop working. I t

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 1.211 (s). 13 q(s)