I want to make my image(thumbnail here) crop to a size as I want when use.
I search and tried the wp_get_attachment_image_src
as told as below, and also other method.
$img_id = get_post_thumbnail_id($post->ID);
$img = wp_get_attachment_image_src(, $image)[0];
echo $img[2];
But still cannot work as expect.
What's the most convenient way to do this? please help.
After 2.5 wordpress don't accept the second parameter $size
of function wp_get_attachment_image_src
to be array of integer size.
But we can add the size as we expect, using:
add_image_size('my-image-size-name', $w, $h, $crop);
But the image resize and cropping would be triggered after this call when image upload.
And when the image uploads after that, the specified size of image thumbnail will be generated. (So the images uploaded before this function call don't create thumbnail images).
And when we want to call this size of thumbnail, we call:
$img_id = get_post_thum
bnail_id($post->ID);
$img = wp_get_attachment_image_src($img_id, 'my-image-size-name')[0];
echo $img[2];
That works.