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()
- How to generate thumbnails when needed only?
- Media files exist in upload folder but not showing up
- Set limit to media upload?
- Save camera info as metadata on image upload?
- How to upload SVG in WordPress 4.9.8?
- How to get all files inserted (but not attached) to a post
- Trigger JS when featured image upload window is opened in admin
- Modify the array of selected images in media modal
- How can I upload SVG images using the media uploader?
- Delete images uploaded by ‘Subscriber’ role
- post_id missing from the wp-admin file upload request
- HTTP Error when uploading mp4 video file
- Change the size of the image preview on the media edit page
- “upload_mimes” filter not working. Need to allow WOFF and WOFF2
- Saving WordPress generated thumbnails in a subdirectory
- Add select field to media uploader that adds a class to the image
- Can’t seem to upload a file to a custom directory
- wp.media add context
- WordPress uploads folder path. how it is decided?
- Split up files from one big folder to multiple folders in uploads after migration
- Display attachments by the ID of the post being edited in the wp.media frame (frontend)
- WordPress uploads autocreate folder every month
- Enabling users to upload files
- Extra “uploads” added in path
- Is there a way to make my media files unsearchable?
- Error uploading images (but the images are at the server!)
- Attach media to post by media category
- Rename attachment filenames to attachment ID on upload
- WordPress Media Library showing wrong preview size?
- Restrict authors to seeing ONLY their media files
- How to edit attachment with media-upload.php?
- How to fix the orientation of images when uploading via the WordPress Media Uploader? [closed]
- Front-end image upload from TinyME [closed]
- WordPress Images, Header Videos and Carousel is not working live but perfect on Local Host Is It FTP? Filezilla?
- Anybody knows if i could upload a leaflet or openlayers3 map to wordpress webpage?
- “Trying to upload files larger than” error will not go away
- Theoretical limit of upload file size [duplicate]
- Remove Media File Items From Server That Do Not Exist in Media Library
- How to add filetype to meta value when using wp_upload_bits?
- Efficient way to move media folder to another folder
- Limit users to specific uploads
- WordPress blog with a custom made theme hosted on heroku
- problem when uploading file by metaboxes
- WordPress Upload Speed
- Organizing the Media Library for Cleanup
- Allow author to upload image via Media button without plugin
- Make custom thumbnail size image in media_sideload_image function
- Upload file to front-end form and send as email attachment
- Host Images from Link
- Upload media error: unable to create directory (windows hosting)
- Can’t upload files 1MB+ [closed]
- I want to customize wp.media (the wordpress admin uploader) in order to change the file name but only in video custom post type