How to manually generate thumbnails?
-
I need to import several hundred images from folders already on the server and attach them to posts. As such, I’ve written a quick script (and borrowed pieces of some plugins) to test the procedure with one image.
After upload, ‘Full size’ reads 0x0 pixels and ‘Thumbnail’ and ‘Medium’ are not configured. I’m having trouble finding any helpful documentation on the functions I need to use. Here’s my script:
$file='wm4hd.jpg'; $filepath=$_SERVER['document_root'].'/wp-content/uploads/2009/04/'.$file; // find TYPE $wp_filetype = wp_check_filetype(basename($file), null ); extract($wp_filetype); if (!$type) $type = ""; $title = 'wm4hd'; $content = ''; $url = 'https://www.example.com/wp-content/uploads/2009/04/'.$file; $file = array( 'file' => $filepath, 'url' => $url, 'type' => $type); $attachment = array( 'guid' => $url, 'post_mime_type' => $type, 'post_title' => $title, 'post_content' => $content, 'post_type' => 'attachment', 'post_parent' => 288 ); $id = wp_insert_attachment($attachment, $filepath, 288); if (!is_wp_error($id)) { wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $filepath)); echo "Imported: $filepath ($title)<br />"; }
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘How to manually generate thumbnails?’ is closed to new replies.