/[drupal]/contributions/modules/imagecrop/imagecrop_actions.inc
ViewVC logotype

Contents of /contributions/modules/imagecrop/imagecrop_actions.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Mon Mar 24 16:29:28 2008 UTC (20 months ago) by swentel
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
File MIME type: text/x-php
Initial import of imagecrop. This module provides an extra imagecache action called javascript_crop and hooks into modules or fields to manipulate images with a javascript toolbox
1 <?php
2
3 /**
4 * Form to add values for javascript form
5 *
6 * @param $data values passed on by imagecache
7 */
8
9 function imagecrop_javascript_form($data) {
10 $form['width'] = array(
11 '#type' => 'textfield',
12 '#title' => t('Width'),
13 '#default_value' => $data['width'],
14 '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'),
15 );
16 $form['height'] = array(
17 '#type' => 'textfield',
18 '#title' => t('Height'),
19 '#default_value' => $data['height'],
20 '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'),
21 );
22 $form['xoffset'] = array(
23 '#type' => 'textfield',
24 '#title' => t('X offset'),
25 '#default_value' => $data['xoffset'],
26 '#description' => t('Enter an offset in pixels or use a keyword: <em>left</em>, <em>center</em>, or <em>right</em>.'),
27 );
28 $form['yoffset'] = array(
29 '#type' => 'textfield',
30 '#title' => t('Y offset'),
31 '#default_value' => $data['yoffset'],
32 '#description' => t('Enter an offset in pixels or use a keyword: <em>top</em>, <em>center</em>, or <em>bottom</em>.'),
33 );
34 $form['resizable'] = array(
35 '#type' => 'checkbox',
36 '#title' => t('Is the toolbox resizable or not?'),
37 '#default_value' => $data['resizable'],
38 );
39 return $form;
40 }
41
42 /**
43 * Display properties of a single action
44 *
45 * @param $element passed on by imagecache
46 * @return string
47 */
48 function theme_imagecrop_javascript($element) {
49 $data = $element['#value'];
50 return 'width: '. $data['width'] .', height: '. $data['height'] .', xoffset: '. $data['xoffset'] .', yoffset: '. $data['yoffset'] .', resizable: '.$data['resizable'];
51 }
52
53 /**
54 * Callback todo the javascript crop action on an image
55 *
56 * @param $image current image resource
57 * @param $data values associated with this action
58 * @param $presetid id of preset
59 * @return false or true
60 */
61 function imagecrop_javascript_image(&$image, $data, $presetid) {
62 $row = db_fetch_object(db_query("SELECT xoffset,yoffset,width,height FROM {imagecrop} ic INNER JOIN {files} f on f.fid = ic.fid WHERE f.filepath = '%s' AND ic.presetid = %d",$image->source,$presetid));
63 if (!empty($row)) {
64 $data['xoffset'] = $row->xoffset;
65 $data['yoffset'] = $row->yoffset;
66 $data['width'] = $row->width;
67 $data['height'] = $row->height;
68 }
69 if (!imageapi_image_crop($image, $data['xoffset'], $data['yoffset'], $data['width'], $data['height'])) {
70 watchdog('imagecrop', t('imagecrop_javascript failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, TRUE))), WATCHDOG_ERROR);
71 return FALSE;
72 }
73 return TRUE;
74 }

  ViewVC Help
Powered by ViewVC 1.1.2