我是 Drupal 新手。
我正在使用 imagemagick 插件来修改图像。我的问题是当它调整 GIF 图像的大小时,图像变得一团糟。我在互联网上搜索了解决方案,我发现了与此相关的变化。 但我不想直接将代码更改写入插件模块文件。 我想覆盖它的 image_imagemagick_resize() 函数。我不知道如何覆盖它以及在哪里放置它的覆盖功能。
默认功能:-
function image_imagemagick_resize(stdClass $image, $width, $height) {
$image->ops[] = '-resize ' . (int) $width . 'x' . (int) $height . '!';
$image->info['width'] = $width;
$image->info['height'] = $height;
return TRUE;
}
覆盖函数:
function imageapi_imagemagick_image_resize(&$image, $width, $height) {
$extra = '';
if($image->info['mime_type'] == 'image/gif') {
$extra = '-coalesce ';
}
$image->ops[] = $extra . '-resize '. (int) $width .'x'. (int) $height .'!';
$image->info['width'] = $width;
$image->info['height'] = $height;
return TRUE;
}
谢谢
答案 0 :(得分:1)
希望 case countryid = "country"
case cityid = "city"
通过 image_imagemagick_resize
调用改变钩子:
_image_imagemagick_alter_invoke
因此您可以通过在自定义模块中实现 function image_imagemagick_resize($source, $dest, $width, $height) {
$args = array('resize' => '-resize ' . (int) $width . 'x' . (int) $height . '!');
$args = _image_imagemagick_alter_invoke('resize', $source, $args);
return _image_imagemagick_convert($source, $dest, $args);
}
function _image_imagemagick_alter_invoke($op, $filepath, $args) {
foreach (module_implements('imagemagick_alter') as $module) {
$function = $module . '_imagemagick_alter';
$function($op, $filepath, $args);
}
return $args;
}
来覆盖调整大小参数:
hook_imagemagick_alter()