如何将上传的图片转换为125x166px缩略图?
// jQuery
wp_enqueue_script('jquery');
// This will enqueue the Media Uploader script
wp_enqueue_media();
var image = wp.media({
title: 'Upload Image',
multiple: false
}).open()
.on('select', function (e) {
// This will return the selected image from the Media Uploader, the result is an object
var uploaded_image = image.state().get('selection').first();
// We convert uploaded_image to a JSON object to make accessing it easier
// Output to the console uploaded_image
console.log(uploaded_image);
var image_url = uploaded_image.toJSON().url;
});
});
答案 0 :(得分:1)
您可以使用wp_get_image_editor
功能。
如何使用的示例可在以下网址获得:https://codex.wordpress.org/Function_Reference/wp_get_image_editor
但这是使用PHP