| 1 |
<?php |
<?php |
| 2 |
// $Id: image_exact.module,v 1.2 2006/02/28 22:51:51 joshk Exp $ |
// $Id: image_exact.module,v 1.3.2.2 2006/06/26 19:04:34 joshk Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 13 |
} |
} |
| 14 |
|
|
| 15 |
/* |
/* |
| 16 |
* Implementation of hook_settings |
* Implementation of hook_menu |
| 17 |
*/ |
*/ |
| 18 |
|
function image_exact_menu($may_cache) { |
| 19 |
|
$items[] = array( |
| 20 |
|
'path' => 'admin/settings/image_exact', |
| 21 |
|
'title' => t('Image Exact'), |
| 22 |
|
'description' => t('Configure the Image Exact module.'), |
| 23 |
|
'callback' => 'drupal_get_form', |
| 24 |
|
'callback arguments' => array('image_exact_admin_settings'), |
| 25 |
|
'access' => user_access('administer site configuration'), |
| 26 |
|
'type' => MENU_NORMAL_ITEM, // optional |
| 27 |
|
); |
| 28 |
|
return $items; |
| 29 |
|
} |
| 30 |
|
|
| 31 |
function image_exact_settings() { |
function image_exact_admin_settings() { |
| 32 |
if (!image_get_toolkit()) { |
if (!image_get_toolkit()) { |
| 33 |
drupal_set_message('You must enable an image toolkit for this module to work!', 'error'); |
drupal_set_message('You must enable an image toolkit for this module to work!', 'error'); |
| 34 |
} |
} |
| 35 |
else { |
else { |
| 36 |
$image_settings = l('image settings page', 'admin/settings/image'); |
$image_settings = l('image settings page', 'admin/settings/image'); |
| 37 |
$user_settings = l('user settings page', 'admin/settings/user'); |
$user_settings = l('user settings page', 'admin/user/settings'); |
| 38 |
$form['image_exact_thumbs'] = array( |
$form['image_exact_nodes'] = array( |
| 39 |
'#type' => 'checkbox', |
'#type' => 'fieldset', |
| 40 |
'#title' => t('Use exact sizes for image-node thumbnails?'), |
'#title' => t('Image Node Settings'), |
| 41 |
'#default_value' => variable_get('image_exact_thumbs', 1), |
'#collapsible' => true, |
| 42 |
'#description' => t('If checked, this will force thumbnails (as defined on the %link) to be exactly the size specified.', array('%link' => $image_settings)), |
'#collapsed' => false, |
| 43 |
); |
); |
| 44 |
if (variable_get('image_exact_avatars', 0)) { |
$form['image_exact_nodes']['image_exact_thumbs'] = array( |
| 45 |
list($final_w, $final_h) = explode('x', variable_get('user_picture_dimensions', '85x85')); |
'#type' => 'checkbox', |
| 46 |
$w = round($final_w / 2); |
'#title' => t('Use exact sizes for image-nodes'), |
| 47 |
$h = round($final_h / 2); |
'#default_value' => variable_get('image_exact_thumbs', 1), |
| 48 |
$form['image_exact_warning'] = array( |
'#description' => t('If checked, this will force images of the size(s) checked below (as defined on the !link) to be exactly the size specified. Otherwise, the settings below will be ignored.', array('!link' => $image_settings)), |
| 49 |
'#title' => t('Exact Avatar Size'), |
); |
| 50 |
'#value' => t('NOTICE: your exact-size avatars will be sized at %w pixels wide and %h pixels tall. To change this enter DOUBLE your desired amount on the %link', array('%link' => $user_settings, '%w' => $w, '%h' => $h)) |
foreach (_image_get_sizes() as $count => $size) { |
| 51 |
|
$options[$count] = $size['label']; |
| 52 |
|
} |
| 53 |
|
$form['image_exact_nodes']['image_exact_size'] = array( |
| 54 |
|
'#type' => 'checkboxes', |
| 55 |
|
'#title' => t('Specific Image Size Settings'), |
| 56 |
|
'#default_value' => variable_get('image_exact_size', array(0)), |
| 57 |
|
'#options' => $options, |
| 58 |
|
'#description' => t('Each image size checked will be cropped and resized to the specified size defined in the !link. Note that existing images will not be resized until viewing that specific image edit tab, and possibly refreshing the browser.', array('!link' => $image_settings)), |
| 59 |
|
); |
| 60 |
|
|
| 61 |
|
if (variable_get('image_exact_avatars', 0)) { |
| 62 |
|
list($final_w, $final_h) = explode('x', variable_get('user_picture_dimensions', '85x85')); |
| 63 |
|
$w = round($final_w / 2); |
| 64 |
|
$h = round($final_h / 2); |
| 65 |
|
$form['image_exact_warning'] = array( |
| 66 |
|
'#title' => t('Exact Avatar Size'), |
| 67 |
|
'#value' => t('NOTICE: your exact-size avatars will be sized at @w pixels wide and @h pixels tall. To change this enter DOUBLE your desired amount on the !link', array('!link' => $user_settings, '@w' => $w, '@h' => $h)) |
| 68 |
|
); |
| 69 |
|
} |
| 70 |
|
$form['image_exact_avatars'] = array( |
| 71 |
|
'#type' => 'checkbox', |
| 72 |
|
'#title' => t('Use exact sizes for avatars?'), |
| 73 |
|
'#default_value' => variable_get('image_exact_avatars', 0), |
| 74 |
|
'#description' => t('Because of how the avatar system works, you need to enter a value in the !link that is DOUBLE what you want the real avatar size to be. If you want 85x85 exact, check the above box, then change the setting on the !link to 170x170', array('!link' => $user_settings)), |
| 75 |
); |
); |
| 76 |
} |
} |
| 77 |
$form['image_exact_avatars'] = array( |
return system_settings_form($form); |
|
'#type' => 'checkbox', |
|
|
'#title' => t('Use exact sizes for avatars?'), |
|
|
'#default_value' => variable_get('image_exact_avatars', 0), |
|
|
'#description' => t('Because of how the avatar system works, you need to enter a value in the %link that is DOUBLE what you want the real avatar size to be. If you want 85x85 exact, check the above box, then change the setting on the %link to 170x170', array('%link' => $user_settings)), |
|
|
); |
|
|
} |
|
|
return $form; |
|
| 78 |
} |
} |
| 79 |
|
|
| 80 |
/* |
/* |
| 86 |
function image_exact_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
function image_exact_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
| 87 |
//Set thumbnail final dimensions here - use settings from image content type. |
//Set thumbnail final dimensions here - use settings from image content type. |
| 88 |
if ($node->type == 'image' && $op == 'validate' && variable_get('image_exact_thumbs', 1)) { |
if ($node->type == 'image' && $op == 'validate' && variable_get('image_exact_thumbs', 1)) { |
| 89 |
$source = file_create_path($node->images['_original']); |
$sizes = _image_get_sizes(); |
| 90 |
$destination = file_create_path($node->images['thumbnail']); |
foreach(variable_get('image_exact_size', array(0)) as $i) { |
| 91 |
$properSizes = variable_get('image_sizes', NULL); |
// for ($i = 0; $i < 5; $i++) { |
| 92 |
$final_w = $properSizes[0]['width']; |
$source = file_create_path($node->images['_original']); |
| 93 |
$final_h = $properSizes[0]['height']; |
$destination = file_create_path($node->images[$sizes[$i]['label']]); |
| 94 |
image_exact_resize($source, $destination, $final_w, $final_h); |
$final_w = $sizes[$i]['width']; |
| 95 |
|
$final_h = $sizes[$i]['height']; |
| 96 |
|
if ($final_w && $final_h) { |
| 97 |
|
image_exact_resize($source, $destination, $final_w, $final_h); |
| 98 |
|
} |
| 99 |
|
} |
| 100 |
} |
} |
| 101 |
} |
} |
| 102 |
|
|
| 119 |
$source_info = image_get_info($source); |
$source_info = image_get_info($source); |
| 120 |
$source_ar = $source_info['width'] / $source_info['height']; |
$source_ar = $source_info['width'] / $source_info['height']; |
| 121 |
if ($source_info['width'] > $final_w && $source_info['height'] > $final_h) { |
if ($source_info['width'] > $final_w && $source_info['height'] > $final_h) { |
| 122 |
// only proceed if we've got a big enough source file... don't stretch a tiny one |
// only proceed if we've got a big enough source file... don't stretch a tiny one |
| 123 |
$final_ar = $final_w / $final_h; |
$final_ar = $final_w / $final_h; |
| 124 |
if($source_ar > $final_ar) { //Too wide! |
if($source_ar > $final_ar) { //Too wide! |
| 125 |
$width = round($source_info['width'] / ($source_ar / $final_ar)); |
$width = round($source_info['width'] / ($source_ar / $final_ar)); |
| 140 |
image_resize($destination, $destination, $final_w, $final_h); |
image_resize($destination, $destination, $final_w, $final_h); |
| 141 |
// drupal_set_message("Resize: $final_w, $final_h",'message'); |
// drupal_set_message("Resize: $final_w, $final_h",'message'); |
| 142 |
if(!file_exists($destination)) { |
if(!file_exists($destination)) { |
| 143 |
drupal-set_message("Image_exact: Image resize failed.","error"); |
drupal_set_message("Image_exact: Image resize failed.","error"); |
| 144 |
} |
} |
| 145 |
} else { |
} else { |
| 146 |
drupal_set_message('image_exact: File does not exist.','error'); |
drupal_set_message('image_exact: File does not exist.','error'); |