Index: imagecache.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.module,v
retrieving revision 1.112.2.5
diff -u -r1.112.2.5 imagecache.module
--- imagecache.module	19 Aug 2009 20:59:07 -0000	1.112.2.5
+++ imagecache.module	2 Nov 2010 12:33:30 -0000
@@ -1103,3 +1103,70 @@
   imagecache_preset_flush($preset);
   imagecache_presets(TRUE);
 }
+
+/**
+ * Implementation of hook_service()
+ */
+function imagecache_service() {
+  return array(    
+
+    array(
+      '#method'   => 'imagecache.get',
+      '#callback' => 'imagecache_service_get',
+      '#access callback'  => 'imagecache_service_get_access',
+      '#args'     => array(
+        array(
+          '#name'         => 'presetname',
+          '#type'         => 'string',
+          '#description'  => t('The name of the preset.'),
+        ),
+        array(
+          '#name'         => 'filepath',
+          '#type'         => 'string',
+          '#description'  => t('The path of the original image.'),
+        )     
+      ),
+      '#return'   => 'string',
+      '#help'     => t('Returns imagecache derivatives path of an image.')),
+    
+  );
+}
+
+/**
+ * Check if the user has the permission to get the imagecache data.
+ *
+ * @param $presetname
+ *   String. The preset name.
+ * @return
+ *   Boolean. TRUE if the user has view access.
+ */
+function imagecache_service_get_access($presetname) {
+  return user_access("view imagecache $presetname");
+}
+
+/**
+ * Build derivative on service calls.
+ * 
+ * @param $presetname
+ *   String. The preset name.
+ * @param $filepath
+ *   String. The path to the file the imagecache is demanded
+ * @return
+ *   String. The path to the imagecache file
+ */
+function imagecache_service_get($presetname, $filepath) {
+
+  if (!$preset = imagecache_preset_by_name($presetname)) {
+    return;
+  }
+  
+  $basepath = base_path();
+  $dst = imagecache_create_path($presetname, $filepath);
+  
+  if (!file_exists($dst)) {
+    imagecache_build_derivative($preset['actions'], $filepath, $dst);
+  }
+
+  return $dst;
+}
+

