Hi,
I'm working on a new imagecache action. I based the work off of this issue: http://drupal.org/node/525852.

I believe that I've properly created the module, and used other actions as the guide for this one, but for some reason when the module is enabled the action doesn't show up under the list of actions that can be added to a preset.

I've tested on a development site with a number of modules enabled, and on a fresh install with only core modules, imagecache, imagecache_actions, and this module enabled.

Any help you can offer with this would be really great.

Here's the code:

imagecache_flip.info:

name = Imagecache Flip
description = Flip an image vertically, horizontally, or both.
dependencies[] = imagecache
package = ImageCache
core = 6.x

imagecache_flip.install:

/**
* @file
* Ensure Imagecache recognises our new actions, per http://drupal.org/node/290101.
*/
function imagecache_flip_enable() {
  cache_clear_all('imagecache_actions', 'cache');
}

function imagecache_flip_disable() {
  cache_clear_all('imagecache_actions', 'cache');
}

imagecache_flip.module:

/**
* Implementation of hook_imagecache_actions().
*/

function imagecache_flipx_imagecache_actions() {
  $actions = array(
    'imagecache_flipx' => array(
      'name' => 'Flip Image Horizontally',
      'description' => 'Flip your images horizontally!',
    ),
  );
}

/**
* Declare dummy form, since we have no settings.
*/

function imagecache_flipx_form() {
  $form = array();
  return $form;
}

/**
* Implementation of hook_imagecache_image().
*/

function imagecache_flipx_image(&$image, $data) {
  $size_x = imagesx($image->resource);
  $size_y = imagesy($image->resource);
  $temp = imagecreatetruecolor($size_x, $size_y);

  //use this line to flip image vertically (upside-down)
  //$x = imagecopyresampled($temp, $image->resource, 0, 0, 0, ($size_y-1), $size_x, $size_y, $size_x, 0-$size_y);

  //use this line to flip image horizontally (right-left)
  $x = imagecopyresampled($temp, $image->resource, 0, 0, ($size_x-1), 0, $size_x, $size_y, 0-$size_x, $size_y);

  if ($x) {
    $image->resource = $temp;
  }
  return $image;
}

Comments

prakashp’s picture

All your hooks are named imagecache_flipx, for example

function imagecache_flipx_image(&$image, $data)

It seems your module name is imagecache_flip, hence all your hooks should be

function imagecache_flip_image(&$image, $data)
seth.vincent’s picture

Ah, thanks. I checked some other actions and found that some put many actions into one module, and based on that I found that I only needed to change the implementation of hook_imagecache_actions().

I changed this:

function imagecache_flipx_imagecache_actions() {

to this:

function imagecache_flip_imagecache_actions() {

I also added return $actions; so it now looks like this:

/**
* Implementation of hook_imagecache_actions().
*/

function imagecache_flip_imagecache_actions() {
  $actions = array(
    'imagecache_flipx' => array(
      'name' => t('Flip Image Horizontally'),
      'description' => t('Flip your images horizontally! (Does not work with transparent images)'),
    ),

  );
  return $actions;
}

----------------------------------

I'm also having a problem with the implementation of hook_imagecache_image(). I've successfully used the code in the function in a custom action (part of the imagecache_actions module), but i'd like to figure out what I'm doing wrong with this function so I understand better how this stuff works.

I'm thinking there's something wrong with this part:

function imagecache_flipx_image(&$image, $data)

Particularly, I think this section: (&$image, $data) is incorrect.

Am I right about that? Or does it look like something else is going on?

jduhls’s picture

I would love this if it works - would make for a great way to do dynamic reflections. Please advise - is this working or should I not bother implementing, yet?