Wordpress:裁剪具有固定值的图像并将其保存在媒体库中
问题描述:
I have a site that periodically get snapshot from a selection of website. Each image has been cropped in a different way and I've saved the crop data for each. Every day the website gets the updated snapshot for each site and I want the crop to be apply to the new image. I found I can crop calling an image editor instance
$img = wp_get_image_editor( ABSPATH.'wp-content/uploads/temp/site_img.jpg' );
if ( ! is_wp_error( $img ) ) {
$img->crop( 130, 110, 107, 145, NULL, NULL, false );
}
How should I use crop and save the cropped image to the media library?
SOLUTION
$image->save( 'new_image.jpg' );
Now it works!!
我有一个网站定期从选定的网站获取快照。 每个图像都以不同的方式裁剪 我已经为每个网站保存了裁剪数据。 每天网站都会获得每个网站的更新快照,我希望将裁剪应用到新图像。 我发现我可以裁剪调用图像编辑器实例 p >
$ img = wp_get_image_editor(ABSPATH.'wp-content / uploads / temp / site_img.jpg');
if(!is_wp_error($ img)){
$ img-&gt ; crop(130,110,107,145,NULL,NULL,false);
}
code> pre>
我应该如何使用裁剪并将裁剪后的图像保存到 媒体库? p>
解决方案 strong> p>
$ image-> save('new_image.jpg');
code> pre>
现在可行!! p>
div>
答
It was easy:
$image->save( 'new_image.jpg' );