Probably not the best title description but here we go. One of my custom post types is for youtube videos which I take the thumb from youtube and upload it as a thumbnail for the post. Now it's easy enough to download the image from youtube and use media_handle_sideload()
to upload it as an attachment for the post and set thumbnail sizes for it be cropped to but youtube video images come with excess black bars at the top and bottom. So I need a way to crop them out.
So I have a custom thumbnail size that crops all thumbs to a width of 224px called 'post-thumbnail'.
I get and process the thumb like so from a front end post.
$vid_url = $_POST['video_url'];
$video_id = getVideoId($vid_url);
if ($video_id) {
$video_response = wp_remote_retrieve_response_code(wp_remote_request($vid_url));
if ($video_response == 200) {
$video_url = $vid_url;
$video_image_url = 'http://img.youtube.com/vi/'.$video_id.'/hqdefault.jpg';
$tmp = download_url($video_image_url);
$file_array = array(
'name' => basename( $video_image_url ),
'tmp_name' => $tmp
);
}
}
$pid = wp_insert_post($new_post);
$vid_thumb = media_handle_sideload( $file_array, $pid );
update_post_meta($pid,'video_thumb',$vid_thumb);
Now this gives me a thumb of 224px/168px so now what I need to do is crop the thumb to 224px/120px knocking off 24px from the top and bottom. Any ideas?