wp_generate_attachment_metadata generates metadata for an image attachment. It also creates a thumbnail and other intermediate sizes of the image attachment based on the sizes defined on the Settings_Media_Screen.
wp_generate_attachment_metadata() is located in wp-admin/includes/image.php.
/* just require image.php before wp_generate_attachment_metadata */
require_once(ABSPATH . ‘wp-admin/includes/image.php’);
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
hope that helps!
Related Posts:
- Upload post thumbnail from the front end
- insert post & Upload post thumbnail from the front end using ajax
- Upload featured image from front end using media-upload.php
- No Thumbnails Generated
- Users can’t upload images on frontend if they haven’t got access to the wp backend
- Differentiate Featured Image from Post Images upon Upload
- Modify featured image path to Amazon S3
- wp_editor with media buttons
- Convert uploaded PNG to JPEG automatically
- front end post with multiple upload images?
- Frontend Simple Local Avatar upload
- Add new media uploader at frontend for wp 3.5+
- Insert Featured image from Feed
- Upload image from a URL and assign it as a Featured Image to a Custom Post Type?
- Close the media-upload thickbox right after upload is finished?
- Regenerate thumbnails unexpected resolution (96 x 96)
- How to change upload directory based on frontend form input name or ID?
- Thumbnails produce unwanted gray pixels on white background [closed]
- Frontend Post – Allow Only Image File Upload
- add_image_size() and uploading the exact size leaves 1×1 image in uploads
- Media Gallery Upload photo incorrect way like glitch
- Attach Thumbnail Generated from Video Upload as Featured Image for the Video
- Front-End Social photo upload [closed]
- Edit User Profile From Front End
- Original image not saving?
- Uploading PDF files from the front-end
- What is the URL pattern for image thumbnails + sizes?
- Upload and attach to a post multiple image files [closed]
- Dynamically determine the width and height of a image file to be cropped & uploaded AFTER form submission given fixed aspect ratio
- Better solution for managing media attachments with `wp_editor()`?
- Upload PDF and other files from the Front-End
- Cropping thumbnails to specific dimensions on front end post
- Removing extra large generated images disables all crops
- Front-End Upload media with category
- Frontend media shows “An error occurred in the upload. Please try again later.”
- Using Gravity Forms to upload media into library, then attach to post
- How can i link my featured image to be clicked and the file will be downloaded
- Redimension thumbnail crop without creating new images
- Featured image to grayscale with PHP imagefilter – which hook to use?
- get the post thumbnail returns the full size
- Is it possible to upload multiple images via Media Library tab in Thickbox I’ve created?
- Make thumbnail from uploaded image without plugin
- Set featured link not showing
- Large front end file uploads on cloud
- Is there a way to force Featured image to show as attachement?
- Link or button to open the media manager from frontend
- How to upload and add images to the existing post from the front-end with admin approval which is posted by other user
- Question regarding the file path for media_sideload_image and wp_upload_dir()
- Plupload Intergration in a meta-box?
- How to Fix HTTP Error When Uploading Images?
- Trigger refresh for new media manager in 3.5
- Physical organization of wordpress media library (Real Media Library plugin)
- Can I upload media to a specific folder?
- wp_upload_dir how to get just the directory name .
- How to generate thumbnails when needed only?
- Limit image upload to one and disable audio, video and other document file types to upload
- How to add new tab to media upload manager with custom set of images?
- Media files exist in upload folder but not showing up
- How to Require a Minimum Image Dimension for Uploading?
- How to upload files straight to S3 without using local storage? [closed]
- Extend Media Library
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- How to set featured image to custom post from outside programmatically
- How to make “Upload files”selected by default in Insert Media?
- WordPress 3.5: Setting custom “full URL path to files” in the Media Library?
- Get $image_id after uploading with media_sideload_image()
- Submit post and upload image from front-end
- simple solution for restricting access to (some) uploads/downloads
- what happens to existing media files when I switch to year/month directory structure format?
- How to disable generation of default image sizes for some custom post types?
- Reject upload of wrong-sized images using the Media Uploader
- WordPress Media Uploader events
- How to show all available images in WP’s media library when using the Polylang plugin?
- how to upload and allow downloads of .mobi and .epub formats
- Allowing WebP uploads?
- Download an image from a webpage to the default uploads folder
- Give users a maximum upload capacity; limit the number of files a user can upload OR limit the number of files per upload
- How to add a custom field to the media screen (image/gallery)?
- Can’t upload media, permissions are correct
- How to assign multiple file-mime-types to extension?
- Saving Media – Which Hook is Fired?
- Set limit to media upload?
- Is it possible to reorganize the WordPress uploads directory?
- WordPress 3.5: Switch back to Old Media Uploader?
- Save camera info as metadata on image upload?
- Media upload finished hook
- How to upload SVG in WordPress 4.9.8?
- How Can I Organize the Uploads Folder by Slug (or ID, or FileType, or Author)?
- How can I batch delete all unattached images with WP-CLI or other automated process?
- Set Featured Image Front Frontend Form
- Create image formats with different qualities when uploading
- Rename files during upload using variables
- Is there a hook which fires after all thumbnails are generated?
- upload_async.php returns 500 error
- Which filters or actions to use after a media upload and delete?
- Organize uploads by year, month and day
- wp_delete_attachment doesn’t delete images in wp-content/uploads/
- Display attachments by ID in a wp.media frame
- Force WordPress 3.3 to use Flash uploader
- Use a separate custom table (not posts) to handle file upload data