Conjuring API

Events happening in the community are now at Drupal community events on www.drupal.org.
heine's picture

ImageMagick integration for Drupal

from http://drupal.org/node/61133

  • Become familiar with the following items: Imagemagick, File API, Image API , Form API
  • Identify x image manipulation actions that could be automated.
  • Identify what processes are required, and how to accomplish them using ImageMagick.
  • Develop functions for each of the operations, clearly documenting their use and parameters.
  • Develop a hook that allows a developer to define 'effects', by specifying a series of operations
    to be called on an image, and a set of parameters.
  • Add additional fields to the upload form to allow the user to select which effect to execute
    for the uploaded images.

Success criteria

  • Develop and document a library that allows access to ImageMagick operations
  • Operations to be included (to be extended)
    -- Layer compositions.
    ---- Must be able to combine two or more layers into a single image.
    ---- Student must decide on which layer composition modes to support (hue, saturation etc)
    ---- All compositions must (be able to?) maintain the translucency of all layers.
    -- Text
    ---- Placing text on images for creation of header images and for the purpose of watermarks and the like.
    -- Gradients
    ---- Create gradients on images, for use in creating custom backgrounds and the like
  • Develop a drupal hook that allows for the creation of 'effects', which are multiple image operations,
    and specific input settings that are used to provide specific graphical effects.
  • Develop an interface that allows newly uploaded images with the upload, or image modules to be
    processed using the imagemagick module.
  • Identify and provide some of the more common effects or processes as part of the imagemagick module,
    with the ability to pre-configure them for use with the upload form.
  • This module must function on all the platform drupal runs on

Points

  • Initial focus on the API, while keeping (future) 'use cases' in mind
  • Pipeline idea

Mockups & ideas

There are several parts to this project
- An API
- An implementation

--> note, it's all conjecture, varnames, hooknames etc need to be considered carefully
--> for starters, I don't like 'effects'

Implement effects

<?php
/**
* Implements an effect  
*  - might consists of multiple steps
* function hook_image_effect_effectname($params) (ps: I don't like the hook name)
*
* The hook implementation makes extending easy
*/
function mymodule_image_effect_blowup ($params, $image) {
 
// Build a proper 'low level' part to go in a conjure file (copied from current inc)
 
$mslfile.='<scale ';
  if (
$params['width']) {
   
$mslfile.='width="'.$params['width'].'" ';
  }
  if(
$params['height']) {
   
$mslfile.='height="'.$params['height'].'" ';
  }
 
$mslfile.='/>';  
  return
$mslfile;
}
?>

Multiple modules implementing one effect are nonsense, so the current image_magick_ prefix might be preferable

Implement calls (api)

You've done this (or something very similar) already

<?php
function some_function($someimage) {
 
$image = $someimage; // an image object
 
$effect[] = array(
   
'type' => 'swirl',
   
'params' => array('degrees' => 40, 'from' => 2)
  );
 
$result = magic($effect, $image);  
}
?>

Implement filters/pipelines

This idea could be even more extended, allowing a kind of input format with different filters stacked
These filters are applied on upload, but the original image is kept so it's possible to regenerate the image

<?php
/**
* Hypothetical, silly example defining a filter for image upload
* @param $op
*   define the operation 'list' or 'process' (make up a nice one)
* @param $delta
*   the effect to retrieve
* @param $image
*   image object (allows one to dynamically alter steps)
*/
function hook_image_filter($op = 'list', $delta = 0, $image = NULL) {
  if (
$op == 'list') {
   
$effect[0] = array('title' => 'resize & swirl', 'description' => 'yaddaya');
   
$effect[1] = array('title' => 'something', 'description' => 'yaddaya');
    return
$effect;
  }
  else if(
$op == 'configure') {
   
// configure the pipeline (only on it's settings page)
 
}
  else if(
$op == 'variables') {
   
// Allow variables to be set when the filter is selected (on upload)
    // needs some thinking
 
}
  else if (
$op == 'process') {
    switch (
$delta) {
      case
0:       
       
$effect[] = array(
         
'type' => 'resize',
         
'params' => array( 'width' => 200, 'height' => 30),   
        );
       
$effect[] = array(
         
'type' => 'swirl',
         
'params' => array('degrees' => 40, 'from' => 2)
        );
       
$pipeline = array('name' => 'afilter', 'description' => 'yaddaya', 'effects' => $effect);
        break;       
      case
1:
       
$effect[] = array(
         
'type' => 'resize',
         
'params' => array( 'width' => 200, 'height' => 30),   
        );
       
$effect[] = array(
         
'type' => 'swirl',
         
'params' => array('degrees' => 40, 'from' => 2)
        );
       
$pipeline = array('name' => 'anotherfilter', 'cache' => FALSE, 'effects' => $effect);      
        break;
    }           
    return
$pipeline;
  }
}
?>

Points

  • caching of the msl file (not always possible - 'cache' => false flag?)
  • the theme might want to resize an image upon output, but that should be handled seperately
  • image file management

Comments

What's progress

sharique's picture

From a long time there isn't any progress on this project.

I really want to see ImageMagick in Drupal core.

Sharique uddin Ahmed Farooqui

Sharique Ahmed Farooqui

SoC 2006: Imagemagick

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week