/[drupal]/contributions/modules/acidfree/image.imagick.inc
ViewVC logotype

Contents of /contributions/modules/acidfree/image.imagick.inc

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


Revision 1.5 - (show annotations) (download) (as text)
Mon Jul 3 14:04:23 2006 UTC (3 years, 4 months ago) by vhmauery
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
Changes since 1.4: +17 -3 lines
File MIME type: text/x-php
* bug fix for path module/album contents interaction (bug 59439)
* fixed imagick toolkit to use jpeg quality
* fix pager to work better in 4.7
* fix so the correct theme stylesheet shows up if a user has
* a different theme selected than the default theme
1 <?php
2 /* $Id: image.imagick.inc,v 1.4 2005/11/09 23:59:37 vhmauery Exp $ */
3
4 /**
5 * Return information about the imagick toolkit
6 */
7 function image_imagick_info() {
8 return array('name' => 'imagick', 'title' => 'Imagick (libmagick6) Toolkit.');
9
10 }
11
12 function image_imagick_check_settings() {
13 if ($check = get_extension_funcs('imagick')) {
14 if (in_array('imagick_readimage', $check)) {
15 return true;
16 }
17 }
18 return false;
19 }
20 /**
21 * Validate and return toolkit specific settings
22 */
23 function image_imagick_settings() {
24 if (!image_imagick_check_settings()) {
25 form_set_error('image_toolkit', t("The built-in imagick image toolkit requires that the imagick module for PHP be installed and configured properly. For more information see %url.", array('%url' => '<a href="http://pecl.php.net/package/imagick</a>')));
26 }
27 $imagick_settings['imagick_imagejpeg_quality'] = array(
28 '#type'=>'textfield',
29 '#title'=>t('Imagick JPEG image quality (1-100)'),
30 '#default_value'=>variable_get('imagick_imagejpeg_quality', 75),
31 );
32 return $imagick_settings;
33 }
34
35 /**
36 * Common helper functions
37 */
38 function _image_imagick_report($handle, $function) {
39 $reason = imagick_failedreason($handle);
40 $description = imagick_faileddescription($handle);
41 drupal_set_message(t('%function failed: %reason: %description',
42 array('%function' => $function, '%reason' => $reason, '%description' => $description)));
43 }
44 function _image_imagick_read($file) {
45 $handle = imagick_readimage($file);
46 if (!$handle) {
47 drupal_set_message(t('imagick_readimage failed to open file %file', array('%file' => $file)));
48 return false;
49 } elseif (imagick_iserror($handle)) {
50 _image_imagick_report($handle, 'imagick_readimage');
51 return false;
52 }
53 return $handle;
54 }
55 function _image_imagick_write($handle, $file) {
56 if (!$handle) {
57 drupal_set_message(t('imagick_readimage failed to open file %file', array('%file' => $file)));
58 return false;
59 } else {
60 if (!imagick_set_image_quality($handle, variable_get('imagick_imagejpeg_quality', 75))) {
61 _image_imagick_report($handle, 'imagick_set_image_quality');
62 return false;
63 }
64 if (!imagick_writeimage($handle, $file)) {
65 _image_imagick_report($handle, 'imagick_writeimage');
66 return false;
67 }
68 }
69 return true;
70 }
71
72 /**
73 * Resize an image to the given width and height
74 */
75 function image_imagick_resize($source, $dest, $width, $height) {
76 if (!($handle = _image_imagick_read($source)))
77 return false;
78 if (!imagick_scale($handle, $width, $height, "!")) {
79 _image_imagick_report($handle, 'imagick_scale');
80 return false;
81 }
82 return _image_imagick_write($handle, $dest);
83 }
84
85 /**
86 * Rotate an image
87 */
88 function image_imagick_rotate($source, $dest, $degrees) {
89 if (!($handle = _image_imagick_read($source)))
90 return false;
91 if (!imagick_rotate($handle, $degrees)) {
92 _image_imagick_report($handle, 'imagick_rotate');
93 return false;
94 }
95 return _image_imagick_write($handle, $dest);
96 }
97
98 /**
99 * Crop an image to the specified dimensions
100 */
101 function image_imagick_crop($source, $dest, $x, $y, $width, $height) {
102 if (!($handle = _image_imagick_read($source)))
103 return false;
104 if (!imagick_crop($handle, $x, $y, $width, $height)) {
105 _image_imagick_report($handle, 'imagick_crop');
106 return false;
107 }
108 return _image_imagick_write($handle, $dest);
109 }
110
111 /**
112 * Composite one image on another
113 */
114 function image_imagick_composite($donkey, $tail, $dest, $x, $y) {
115 if (!($handle = _image_imagick_read($donkey)))
116 return false;
117 if (!($comp_handle = _image_imagick_read($tail)))
118 return false;
119 imagick_composite($handle, IMAGICK_COMPOSITE_OP_OVER,
120 $comp_handle, 200, 200);
121 return _image_imagick_write($handle, $dest);
122 }
123
124 ?>

  ViewVC Help
Powered by ViewVC 1.1.2