当我在wordpress中上传一张图片时,我知道它的尺寸。假设图像名为image.jpg。例如,我希望wordpress将图像url重命名为image-w- 180 -h-200.jpg (其中图像的宽度为180像素,高度为200像素)。有没有什么办法我可以把这些细节附加到url上,这样我就可以直接‘检索’这些参数了?(我的目标是最终通过javascript获得img的宽度和高度,但通过这种方式,我不必预先加载img来获取它的尺寸,wordpress已经为我完成了这项工作)
干杯!
发布于 2012-12-11 08:26:04
(改编自https://wordpress.stackexchange.com/questions/38582/hook-to-get-image-filename-when-it-is-uploaded)
function rename_image($results) {
if( $results['type'] === 'image/jpeg' ) { // or /png or /tif / /whatever
$filename = $results[ 'file' ]; // Use this line to add height and width of image;
$url = $results[ 'url' ];
// manipulate the image
}
}
add_action('wp_handle_upload', 'rename_image');有关这方面的更多信息,请阅读指定的URL
https://stackoverflow.com/questions/13811606
复制相似问题