patch attached.

On 10/3/06, Edward Duffy <[EMAIL PROTECTED]> wrote:
On 10/3/06, Jamie McCracken <[EMAIL PROTECTED]> wrote:
> René Stadler wrote:
> > Am Dienstag, den 03.10.2006, 12:50 +0100 schrieb Jamie McCracken:
> > [...]
> >> I think for image files (gif, tiff and others) we might want to use
> >> imageMagick's identify command to get the dimensions (especially if
> >> libexif and libpng are not present as we can fallback on this too)
> >>
> >> EG
> >>
> >> identify -format "%wx%h"   sample.jpg
> >> 2112x2720
> >>
> >>
> >> this will allow us to get the Image.Width and Image.Height by parsing
> >> stdout. We also dont need a hard dependency on ImageMagicks stuff.
> >>
> >> It can also be used to get comments embedded and other stuff like
> >> resolutions in image :
> >>
> >> identify -format "%c"   sample.jpg
> >>
> > [...]
> >
> > Using identify might be a bad idea.  Last time I checked, it had the bad
> > habit of performing all of its extraction and analysis capabilities
> > (counting colors etc.) even if you just request things as simple as the
> > geometry or the embedded comment (which should become available after
> > just parsing a few bytes of most image formats).  That is, it is very
> > slow/wastes CPU cycles.  For getting the geometry, I found that it is
> > much faster and efficient to use a GdkPixbufLoader and connect to the
> > "size-prepared" signal.  Not that I think this is the perfect solution
> > either (I think GdkPixbuf has already allocated memory to hold the
> > complete decoded image when it emits the signal), but it tells about the
> > deficiencies of Imagemagick.
> >
>
> yes you might be right there (identify does seem a little slow on large
> images)
>

It's not slow if you use the "-ping" parameter.  Just a quick test
with over 200 images, it took over 1 minute to run identify all images
(most around 2MB), and 5 seconds with the -ping parameter.

Shouldn't take me long to do this.
> We cant depend on GDK either.
>
> I only suggested it as a fallback for images not supported by libexif or
> libpng (which means stuff like tiff, gif, xpm et all). If we have time
> we can extract libextractor's plugins for these other formats which
> should be more efficient.
>
> --
> Mr Jamie McCracken
> http://jamiemcc.livejournal.com/
>

Index: src/tracker-extract/tracker-extract.c
===================================================================
RCS file: /cvs/gnome/tracker/src/tracker-extract/tracker-extract.c,v
retrieving revision 1.12
diff -u -p -r1.12 tracker-extract.c
--- src/tracker-extract/tracker-extract.c	3 Oct 2006 11:37:09 -0000	1.12
+++ src/tracker-extract/tracker-extract.c	3 Oct 2006 15:02:45 -0000
@@ -141,45 +141,43 @@ void tracker_extract_png   (gchar *, GHa
 #ifdef HAVE_LIBEXIF
 void tracker_extract_exif   (gchar *, GHashTable *);
 #endif
+void tracker_extract_imagemagick   (gchar *, GHashTable *);
 
 MimeToExtractor extractors[] = {
    /* Document extractors */
-	{ "application/vnd.oasis.opendocument.text",         tracker_extract_oasis },
-	{ "application/vnd.oasis.opendocument.spreadsheet",  tracker_extract_oasis },
-	{ "application/vnd.oasis.opendocument.graphics",     tracker_extract_oasis },
-	{ "application/vnd.oasis.opendocument.presentation", tracker_extract_oasis },
-	{ "application/postscript",                          tracker_extract_ps    },
+	{ "application/vnd.oasis.opendocument.*",       tracker_extract_oasis       },
+	{ "application/postscript",                     tracker_extract_ps          },
 #ifdef HAVE_POPPLER
-	{ "application/pdf",                                 tracker_extract_pdf   },
+	{ "application/pdf",                            tracker_extract_pdf         },
 #endif
-	{ "application/x-abiword",                           tracker_extract_abw   },
+	{ "application/x-abiword",                      tracker_extract_abw         },
 #ifdef HAVE_LIBGSF
-	{ "application/msword",                              tracker_extract_msoffice   },
-	{ "application/vnd.ms-excel",                        tracker_extract_msoffice   },
-	{ "application/vnd.ms-powerpoint",                   tracker_extract_msoffice   },
+	{ "application/msword",                         tracker_extract_msoffice    },
+	{ "application/vnd.ms-*",                       tracker_extract_msoffice    },
 #endif
 
 
    /* Video extractors */
 #ifdef HAVE_THEORA
-	{ "video/x-theora+ogg",                              tracker_extract_theora   },
+	{ "video/x-theora+ogg",                         tracker_extract_theora      },
 #endif
 
 
    /* Audio extractors */
 #ifdef HAVE_VORBIS
-	{ "audio/x-vorbis+ogg",                              tracker_extract_vorbis   },
+	{ "audio/x-vorbis+ogg",                         tracker_extract_vorbis      },
 #endif
 
 
    /* Image extractors */
 #ifdef HAVE_LIBPNG
-	{ "image/png",                                       tracker_extract_png   },
+	{ "image/png",                                  tracker_extract_png         },
 #endif
 #ifdef HAVE_LIBEXIF
-	{ "image/jpeg",                                       tracker_extract_exif   },
+	{ "image/jpeg",                                 tracker_extract_exif        },
 #endif
-	{ "",                                                NULL                           }
+	{ "image/*",                                    tracker_extract_imagemagick },
+	{ "",                                           NULL                        }
 };
 
 static MetadataFileType
@@ -456,7 +454,7 @@ tracker_get_file_metadata (const char *u
 	if (mime) {
 		MimeToExtractor  *p;
 		for (p = extractors; p->extractor; ++p) {
-			if (strcmp (p->mime, mime) == 0) {
+			if (g_pattern_match_simple (p->mime, mime)) {
 				(*p->extractor)(uri_in_locale, meta_table);
 				return meta_table;
 			}
--- /dev/null	2006-08-05 19:53:54.000000000 -0400
+++ src/tracker-extract/tracker-extract-imagemagick.c	2006-10-03 11:01:11.000000000 -0400
@@ -0,0 +1,40 @@
+
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+
+void
+tracker_extract_imagemagick (gchar *filename, GHashTable *metadata)
+{
+	gchar         *argv[6];
+	gchar         *identify;
+	gchar        **lines;
+	gchar        **size;
+
+	argv[0] = g_strdup ("identify");
+	argv[1] = g_strdup ("-format");
+	argv[2] = g_strdup ("%wx%h\\n");  /* \n because of ani-gif */
+	argv[3] = g_strdup ("-ping");
+	argv[4] = g_strdup (filename);
+	argv[5] = NULL;
+
+	if(g_spawn_sync (NULL,
+	                 argv,
+	                 NULL,
+	                 G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
+	                 NULL,
+	                 NULL,
+	                 &identify,
+	                 NULL,
+	                 NULL,
+	                 NULL)) {
+
+		lines = g_strsplit (identify, "\n", 2);
+		size = g_strsplit (lines[0], "x", 2);
+		g_hash_table_insert (metadata, g_strdup ("Image.Width"), g_strdup (size[0]));
+		g_hash_table_insert (metadata, g_strdup ("Image.Height"), g_strdup (size[1]));
+	}
+}
+
_______________________________________________
tracker-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/tracker-list

Reply via email to