I'm trying to create my first plugin. The bit that I'm working on now is supposed to read the post title and create an image with that text in it. But for some reason it's not saving the image. Here's what I have:
// Get the post title from the post
$post_data = get_post($post->ID, ARRAY_A);
$post_slug = $post_data['post_name'];
$post_title = get_the_title( $post_id );
// Generate the image
$new_img = imagecreatetruecolor( 200, 80 );
$background = imagecolorallocate( $new_img, 200, 200, 200 );
$text_color = imagecolorallocate( $new_img, 150, 100, 100 );
$line_color = imagecolorallocate( $new_img, 128, 255, 0 );
imagestring( $new_img, 4, 30, 25, "$post_title", $text_color );
imagesetthickness ( $new_featured_img, 5 );
imageline( $new_featured_img, 30, 45, 165, 45, $line_color );
// Save the image
$upload_dir = wp_upload_dir();
$upload_dir_path = $upload_dir['baseurl'];
imagejpeg( $new_featured_img, "$upload_dir_path/$post_slug.jpg" );
imagecolordeallocate( $new_featured_img, $line_color );
imagecolordeallocate( $new_featured_img, $text_color );
imagecolordeallocate( $new_featured_img, $background );
}
Here are the warnings it gives me:
Warning: imagejpeg() [function.imagejpeg]: Unable to open 'http://pastorhuff.com/wp-content/uploads/what-happens-in-a-fallen-world.jpg' for writing: No such file or directory in /home/pastor/public_html/wp-content/plugins/auto-featured-image-from-title/auto-featured-image-from-title.php on line 35
Warning: Cannot modify header information - headers already sent by (output started at /home/pastor/public_html/wp-content/plugins/auto-featured-image-from-title/auto-featured-image-from-title.php:35) in /home/pastor/public_html/wp-admin/post.php on line 222
Warning: Cannot modify header information - headers already sent by (output started at /home/pastor/public_html/wp-content/plugins/auto-featured-image-from-title/auto-featured-image-from-title.php:35) in /home/pastor/public_html/wp-includes/pluggable.php on line 875
Would greatly appreciate any guidance. Thanks.