Closed (fixed)
Project:
ImageCache
Version:
6.x-2.x-dev
Component:
Code
Priority:
Minor
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
27 May 2010 at 20:37 UTC
Updated:
24 May 2012 at 07:54 UTC
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
Comment #1
seth.vincent commentedOops. Feature request isn't a sensible category. Changed to support request.
Comment #2
dman commentedMethinks a
return $actions;would be handy there?:-)
Comment #3
seth.vincent commentedAh, dang! Thanks, I should have caught that.
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, 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?
This is far from urgent, but if you see anything in that function that seems wonky, I'd really appreciate a little help.
Comment #4
dman commentedWell for hook_image, the return is a bool for success. The $image->resource is updated by reference.
But you should still be getting results, and you'd be seeing an error otherwise.
I don't know about flipping beyond what I see on php.net
http://nz2.php.net/manual/en/function.imagecopy.php#89658
For info about the imagecache API, see the imagecache project proper. All I've done in 'actions' is make stuff up based on inspection of what I found there. Sending thread over there.
Comment #5
fizk commented