在使用 imagecache_create_path & 之前使用 Drupal imagecache 生成图像获取图像大小
我使用 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 生成图像(使用预设)而不在浏览器中显示它吗?
先感谢您
I'm using imagecache_create_path() and getimagesize() to get the path of a imagecache-generated image and its dimensions. However, if it's the first time we access the page that image doesn't exist yet and imagecache_create_path doesn't generate it either.
Here's the code:
// 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);
Is there any API method to get the path AND generate the file? In other words, can I generate the image (using a preset) from PHP without showing it in the browser?
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查 imagecache.module 中的
imagecache_build_derivative()
函数及其用法。对于您的情况,它应该大致如下工作:(注意:未经测试的代码,谨防拼写错误和其他错误/疏忽)
Check the
imagecache_build_derivative()
function and its usage in imagecache.module. For your case, it should work roughly like so:(NOTE: untested code, beware of typos and other errors/oversights)