在wordpress中将图像裁剪到一定大小
我试图将图像裁剪到某个特定的位置 我试过使用在wordpress中将图像裁剪到一定大小,wordpress,Wordpress,我试图将图像裁剪到某个特定的位置 我试过使用 add_image_size( 'other', 105, 70, true ); $imageString.= '<div><a href="' . $linkstring . '">' . get_the_post_thumbnail($post->ID, 'other;) . '</a></div>'; 添加图像大小('other',105,70,true); $imageString.
add_image_size( 'other', 105, 70, true );
$imageString.= '<div><a href="' . $linkstring . '">' . get_the_post_thumbnail($post->ID, 'other;) . '</a></div>';
添加图像大小('other',105,70,true);
$imageString.='';
但它似乎并没有达到那个精确的尺寸
任何IDE?与图像大小调整和裁剪相关的功能都放在media.php中
例如,开始阅读有关图像大小尺寸的内容,这也将为您提供裁剪尺寸。然后,这些尺寸可以与imagecopyresampled一起使用。通常,您可以将图像尺寸添加到functions.php文件中
//post thumbnail support
add_action( 'after_setup_theme', 'theme_setup' );
function theme_setup() {
if ( function_exists( 'add_theme_support' ) ) {
add_image_size( 'other', 105, 70, true );
}
}
然后,一旦到位,wordpress将为所有新上传的图像创建一个相同大小的图像
如果要为已上载的图像创建这些图像大小,请查看我的经验中的“获取”\u如果使用添加图像大小的自定义图像大小,则“发布”缩略图并不总是有效 我建议您使用add_image_size,但通过wp_get_attachment_image_src获取图像,如下所示:
$imageurl = wp_get_attachment_image_src($attachment->ID, "other" );
$imageString.= '<div><a href="' . $linkstring . '"><img src="' . $imageurl[0] . '"/></a></div>';
$imageurl=wp\u get\u attachment\u image\u src($attachment->ID,“other”);
$imageString.='';
wp\u get\u attachment\u image\u src不将post ID作为参数。它需要一个附件id。