我使用 imagecache_create_path() 和 getimagesize() 来获取 imagecache 生成的图像的路径及其尺寸。但是,如果这是我们第一次访问该页面,则该图像尚不存在,并且 imagecache_create_path 也不会生成它。
这是代码:
// we get the image path from a preset (always return the path even if the file doesn't exist)
$small_image_path = imagecache_create_path('gallery_image_small', $image["filepath"]);
// I get the image dimensions (only if the file exists already)
$data_small = list($width, $height, $type, $image_attributes) = @getimagesize($small_image_path);
有没有API方法可以获取路径并生成文件?换句话说,我可以从 PHP 生成图像(使用预设)而不在浏览器中显示吗?
先感谢您
检查imagecache_build_derivative()
imagecache.module 中的函数及其用法。对于您的情况,它应该大致如下工作:
$presetname = 'gallery_image_small';
$preset = imagecache_preset_by_name($presetname);
$src = $image["filepath"];
$dst = imagecache_create_path($presetname, $src);
// Ensure existing derivative or try to create it on the fly
if (file_exists($dst) || imagecache_build_derivative($preset['actions'], $src, $dst)) {
// Do what you need to do with the image
}
(注意:未经测试的代码,谨防拼写错误和其他错误/疏忽)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)