function _textimage_background_image_resize in Textimage 7.3
Recalculate background image size.
When wrapper overflows the original image, and autoextent is set on.
2 calls to _textimage_background_image_resize()
- textimage_text_effect in effects/
textimage_text.inc - Implements 'textimage_text' image effect callback.
- textimage_text_effect_dimensions in effects/
textimage_text.inc - Implements 'textimage_text' image dimensions callback.
File
- effects/
textimage_text.inc, line 1020 - Implementation of the 'textimage_text' image effect.
Code
function _textimage_background_image_resize($image, $wrapper, $data, &$image_new, &$frame = NULL) {
$resized = FALSE;
// Background image dimensions.
$image_width = $image->info['width'];
$image_height = $image->info['height'];
// Wrapper image dimensions.
$wrapper_width = $wrapper->info['width'];
$wrapper_height = $wrapper->info['height'];
// Determine wrapper offset, based on placement option.
// This is just taking into account the image and wrapper dimensions;
// additional offset explicitly specified is considered later.
$x_offset = ceil(image_filter_keyword($data['layout']['x_pos'], $image_width, $wrapper_width));
$y_offset = ceil(image_filter_keyword($data['layout']['y_pos'], $image_height, $wrapper_height));
// The position of the wrapper, once offset as per explicit
// input. Width and height are not relevant for the algorithm,
// but would be determined as follows:
// Width:
// if ($wrapper_width < $image_width) then
// $wrapper_width + abs($data['layout']['x_offset']) else
// $wrapper_width
// Height:
// if ($wrapper_height < $image_height) then
// $wrapper_height + abs($data['layout']['y_offset']) else
// $wrapper_height
$offset_wrapper = array(
'xpos' => $x_offset + $data['layout']['x_offset'],
'ypos' => $y_offset + $data['layout']['y_offset'],
);
// If offset wrapper overflows to the left, background image
// will be shifted to the right.
if ($offset_wrapper['xpos'] < 0) {
$image_new['width'] = $image_width - $offset_wrapper['xpos'];
$image_new['xpos'] = -$offset_wrapper['xpos'];
$offset_wrapper['xpos'] = 0;
if (isset($frame)) {
$frame['left'] = $image_new['width'] - $image_width;
}
$resized = TRUE;
}
// If offset wrapper overflows to the top, background image
// will be shifted to the bottom.
if ($offset_wrapper['ypos'] < 0) {
$image_new['height'] = $image_height - $offset_wrapper['ypos'];
$image_new['ypos'] = -$offset_wrapper['ypos'];
$offset_wrapper['ypos'] = 0;
if (isset($frame)) {
$frame['top'] = $image_new['height'] - $image_height;
}
$resized = TRUE;
}
// If offset wrapper overflows to the right, background image
// will be extended to the right.
if ($offset_wrapper['xpos'] + $wrapper_width > $image_new['width']) {
$tmp = $image_new['width'];
$image_new['width'] = $offset_wrapper['xpos'] + $wrapper_width;
if (isset($frame)) {
$frame['right'] = $image_new['width'] - $tmp;
}
$resized = TRUE;
}
// If offset wrapper overflows to the bottom, background image
// will be extended to the bottom.
if ($offset_wrapper['ypos'] + $wrapper_height > $image_new['height']) {
$tmp = $image_new['height'];
$image_new['height'] = $offset_wrapper['ypos'] + $wrapper_height;
if (isset($frame)) {
$frame['bottom'] = $image_new['height'] - $tmp;
}
$resized = TRUE;
}
return array(
$resized,
$offset_wrapper,
);
}