function imagecache_asset_formatter in Asset 5
Same name and namespace in other branches
- 5.2 modules/asset_imagecache.inc \imagecache_asset_formatter()
- 6 modules/asset_imagecache.inc \imagecache_asset_formatter()
- 6 inc/modules/asset_imagecache.inc \imagecache_asset_formatter()
File
- modules/
asset_imagecache.inc, line 20
Code
function imagecache_asset_formatter($op = 'info', $asset = null, $attr = array()) {
switch ($op) {
case 'info':
$presets = imagecache_presets();
foreach ($presets as $preset) {
if (variable_get('asset_imagecache_preset_' . $preset['presetid'], 1)) {
$formats[$preset['presetname']] = array(
'name' => $preset['presetname'] . ' (imagecache)',
'types' => array(
'local' => array(
'jpg',
'gif',
'png',
),
),
);
}
}
return $formats;
case 'options':
$path = imagecache_create_path($attr['format'], $asset->filepath);
if (!file_exists($path)) {
// this is the easiest albeit indirect way i can see to generate the image
$result = drupal_http_request(url(file_create_url($path)));
}
$size = image_get_info(imagecache_create_path($attr['format'], $asset->filepath));
$form['width'] = array(
'#type' => 'hidden',
'#value' => $size['width'],
);
$form['height'] = array(
'#type' => 'hidden',
'#value' => $size['height'],
);
$form['resizable'] = array();
$form['_width'] = array(
'#type' => 'item',
'#title' => t('Width, preset by imagecache'),
'#value' => $size['width'] . 'px',
);
$form['_height'] = array(
'#type' => 'item',
'#title' => t('Height, preset by imagecache'),
'#value' => $size['height'] . 'px',
);
return $form;
break;
case 'img':
return imagecache_create_path($attr['format'], $asset->filepath);
case 'preview':
return theme('imagecache', $attr['format'], $asset->filepath, '', '', array(
'width' => '100',
));
case 'render':
return theme('imagecache', $attr['format'], $asset->filepath, $attr['title'], $attr['title'], array(
'id' => 'image_' . $attr['format'] . '_' . $attr['aid'],
));
}
}