{"id":24263882,"url":"https://github.com/wp-cli/media-command","last_synced_at":"2026-03-04T16:03:21.883Z","repository":{"id":17382479,"uuid":"81869666","full_name":"wp-cli/media-command","owner":"wp-cli","description":"Imports files as attachments, regenerates thumbnails, or lists registered image sizes.","archived":false,"fork":false,"pushed_at":"2025-05-12T18:27:41.000Z","size":8815,"stargazers_count":43,"open_issues_count":19,"forks_count":41,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-12T19:44:35.254Z","etag":null,"topics":["cli","hacktoberfest","media","regeneration","thumbnail","upload","wordpress","wp-cli","wp-cli-package"],"latest_commit_sha":null,"homepage":"","language":"Gherkin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wp-cli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-02-13T20:43:13.000Z","updated_at":"2025-05-12T18:27:43.000Z","dependencies_parsed_at":"2024-02-22T12:31:42.245Z","dependency_job_id":"6664cc78-1894-4eb3-a620-26c4c457c761","html_url":"https://github.com/wp-cli/media-command","commit_stats":{"total_commits":721,"total_committers":70,"mean_commits":10.3,"dds":0.7545076282940361,"last_synced_commit":"0e7d1fbc7170d8c2b8a2779f0cd3aebbf582b22b"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fmedia-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fmedia-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fmedia-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fmedia-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wp-cli","download_url":"https://codeload.github.com/wp-cli/media-command/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414499,"owners_count":22067272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","hacktoberfest","media","regeneration","thumbnail","upload","wordpress","wp-cli","wp-cli-package"],"created_at":"2025-01-15T08:52:17.407Z","updated_at":"2026-03-04T16:03:21.874Z","avatar_url":"https://github.com/wp-cli.png","language":"Gherkin","readme":"wp-cli/media-command\n====================\n\nImports files as attachments, regenerates thumbnails, or lists registered image sizes.\n\n[![Testing](https://github.com/wp-cli/media-command/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/media-command/actions/workflows/testing.yml)\n\nQuick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing) | [Support](#support)\n\n## Using\n\nThis package implements the following commands:\n\n### wp media\n\nImports files as attachments, regenerates thumbnails, or lists registered image sizes.\n\n~~~\nwp media\n~~~\n\n**EXAMPLES**\n\n    # Re-generate all thumbnails, without confirmation.\n    $ wp media regenerate --yes\n    Found 3 images to regenerate.\n    1/3 Regenerated thumbnails for \"Sydney Harbor Bridge\" (ID 760).\n    2/3 Regenerated thumbnails for \"Boardwalk\" (ID 757).\n    3/3 Regenerated thumbnails for \"Sunburst Over River\" (ID 756).\n    Success: Regenerated 3 of 3 images.\n\n    # Import a local image and set it to be the featured image for a post.\n    $ wp media import ~/Downloads/image.png --post_id=123 --title=\"A downloaded picture\" --featured_image\n    Imported file '/home/person/Downloads/image.png' as attachment ID 1753 and attached to post 123 as featured image.\n    Success: Imported 1 of 1 images.\n\n    # List all registered image sizes\n    $ wp media image-size\n    +---------------------------+-------+--------+-------+\n    | name                      | width | height | crop  |\n    +---------------------------+-------+--------+-------+\n    | full                      |       |        | N/A   |\n    | twentyfourteen-full-width | 1038  | 576    | hard  |\n    | large                     | 1024  | 1024   | soft  |\n    | medium_large              | 768   | 0      | soft  |\n    | medium                    | 300   | 300    | soft  |\n    | thumbnail                 | 150   | 150    | hard  |\n    +---------------------------+-------+--------+-------+\n\n    # Fix orientation for specific images.\n    $ wp media fix-orientation 63\n    1/1 Fixing orientation for \"Portrait_6\" (ID 63).\n    Success: Fixed 1 of 1 images.\n\n\n\n### wp media fix-orientation\n\nFix image orientation for one or more attachments.\n\n~~~\nwp media fix-orientation [\u003cattachment-id\u003e...] [--dry-run]\n~~~\n\n**OPTIONS**\n\n\t[\u003cattachment-id\u003e...]\n\t\tOne or more IDs of the attachments to regenerate.\n\n\t[--dry-run]\n\t\tCheck images needing orientation without performing the operation.\n\n**EXAMPLES**\n\n    # Fix orientation for all images.\n    $ wp media fix-orientation\n    1/3 Fixing orientation for \"Landscape_4\" (ID 62).\n    2/3 Fixing orientation for \"Landscape_3\" (ID 61).\n    3/3 Fixing orientation for \"Landscape_2\" (ID 60).\n    Success: Fixed 3 of 3 images.\n\n    # Fix orientation dry run.\n    $ wp media fix-orientation 63 --dry-run\n    1/1 \"Portrait_6\" (ID 63) will be affected.\n    Success: 1 of 1 image will be affected.\n\n    # Fix orientation for specific images.\n    $ wp media fix-orientation 63\n    1/1 Fixing orientation for \"Portrait_6\" (ID 63).\n    Success: Fixed 1 of 1 images.\n\n\n\n### wp media import\n\nCreates attachments from local files or URLs.\n\n~~~\nwp media import \u003cfile\u003e... [--post_id=\u003cpost_id\u003e] [--post_name=\u003cpost_name\u003e] [--file_name=\u003cname\u003e] [--title=\u003ctitle\u003e] [--caption=\u003ccaption\u003e] [--alt=\u003calt_text\u003e] [--desc=\u003cdescription\u003e] [--skip-copy] [--destination-dir=\u003cdestination-dir\u003e] [--preserve-filetime] [--featured_image] [--porcelain[=\u003cfield\u003e]]\n~~~\n\n**OPTIONS**\n\n\t\u003cfile\u003e...\n\t\tPath to file or files to be imported. Supports the glob(3) capabilities of the current shell.\n\t\t    If file is recognized as a URL (for example, with a scheme of http or ftp), the file will be\n\t\t    downloaded to a temp file before being sideloaded.\n\n\t[--post_id=\u003cpost_id\u003e]\n\t\tID of the post to attach the imported files to.\n\n\t[--post_name=\u003cpost_name\u003e]\n\t\tName of the post to attach the imported files to.\n\n\t[--file_name=\u003cname\u003e]\n\t\tAttachment name (post_name field).\n\n\t[--title=\u003ctitle\u003e]\n\t\tAttachment title (post title field).\n\n\t[--caption=\u003ccaption\u003e]\n\t\tCaption for attachment (post excerpt field).\n\n\t[--alt=\u003calt_text\u003e]\n\t\tAlt text for image (saved as post meta).\n\n\t[--desc=\u003cdescription\u003e]\n\t\t\"Description\" field (post content) of attachment post.\n\n\t[--skip-copy]\n\t\tIf set, media files (local only) are imported to the library but not moved on disk.\n\t\tFile names will not be run through wp_unique_filename() with this set. When used, files\n\t\twill remain at their current location and will not be copied into any destination directory.\n\n\t[--destination-dir=\u003cdestination-dir\u003e]\n\t\tPath to the destination directory for uploaded imported files.\n\t\tCan be absolute or relative to ABSPATH. Ignored when used together with --skip-copy, as\n\t\tfiles are not moved on disk in that case.\n\n\t[--preserve-filetime]\n\t\tUse the file modified time as the post published \u0026 modified dates.\n\t\tRemote files will always use the current time.\n\n\t[--featured_image]\n\t\tIf set, set the imported image as the Featured Image of the post it is attached to.\n\n\t[--porcelain[=\u003cfield\u003e]]\n\t\tOutput a single field for each imported image. Defaults to attachment ID when used as flag.\n\t\t---\n\t\toptions:\n\t\t  - url\n\t\t---\n\n**EXAMPLES**\n\n    # Import all jpgs in the current user's \"Pictures\" directory, not attached to any post.\n    $ wp media import ~/Pictures/**\\/*.jpg\n    Imported file '/home/person/Pictures/landscape-photo.jpg' as attachment ID 1751.\n    Imported file '/home/person/Pictures/fashion-icon.jpg' as attachment ID 1752.\n    Success: Imported 2 of 2 items.\n\n    # Import a local image and set it to be the post thumbnail for a post.\n    $ wp media import ~/Downloads/image.png --post_id=123 --title=\"A downloaded picture\" --featured_image\n    Imported file '/home/person/Downloads/image.png' as attachment ID 1753 and attached to post 123 as featured image.\n    Success: Imported 1 of 1 images.\n\n    # Import a local image, but set it as the featured image for all posts.\n    # 1. Import the image and get its attachment ID.\n    # 2. Assign the attachment ID as the featured image for all posts.\n    $ ATTACHMENT_ID=\"$(wp media import ~/Downloads/image.png --porcelain)\"\n    $ wp post list --post_type=post --format=ids | xargs -d ' ' -I % wp post meta add % _thumbnail_id $ATTACHMENT_ID\n    Success: Added custom field.\n    Success: Added custom field.\n\n    # Import an image from the web.\n    $ wp media import http://s.wordpress.org/style/images/wp-header-logo.png --title='The WordPress logo' --alt=\"Semantic personal publishing\"\n    Imported file 'http://s.wordpress.org/style/images/wp-header-logo.png' as attachment ID 1755.\n    Success: Imported 1 of 1 images.\n\n    # Get the URL for an attachment after import.\n    $ wp media import http://s.wordpress.org/style/images/wp-header-logo.png --porcelain | xargs -I {} wp post list --post__in={} --field=url --post_type=attachment\n    http://wordpress-develop.dev/wp-header-logo/\n\n\n\n### wp media regenerate\n\nRegenerates thumbnails for one or more attachments.\n\n~~~\nwp media regenerate [\u003cattachment-id\u003e...] [--image_size=\u003cimage_size\u003e] [--skip-delete] [--only-missing] [--delete-unknown] [--yes]\n~~~\n\n**OPTIONS**\n\n\t[\u003cattachment-id\u003e...]\n\t\tOne or more IDs of the attachments to regenerate.\n\n\t[--image_size=\u003cimage_size\u003e]\n\t\tName of the image size to regenerate. Only thumbnails of this image size will be regenerated, thumbnails of other image sizes will not.\n\n\t[--skip-delete]\n\t\tSkip deletion of the original thumbnails. If your thumbnails are linked from sources outside your control, it's likely best to leave them around. Defaults to false.\n\n\t[--only-missing]\n\t\tOnly generate thumbnails for images missing image sizes.\n\n\t[--delete-unknown]\n\t\tOnly delete thumbnails for old unregistered image sizes.\n\n\t[--yes]\n\t\tAnswer yes to the confirmation message. Confirmation only shows when no IDs passed as arguments.\n\n**EXAMPLES**\n\n    # Regenerate thumbnails for given attachment IDs.\n    $ wp media regenerate 123 124 125\n    Found 3 images to regenerate.\n    1/3 Regenerated thumbnails for \"Vertical Image\" (ID 123).\n    2/3 Regenerated thumbnails for \"Horizontal Image\" (ID 124).\n    3/3 Regenerated thumbnails for \"Beautiful Picture\" (ID 125).\n    Success: Regenerated 3 of 3 images.\n\n    # Regenerate all thumbnails, without confirmation.\n    $ wp media regenerate --yes\n    Found 3 images to regenerate.\n    1/3 Regenerated thumbnails for \"Sydney Harbor Bridge\" (ID 760).\n    2/3 Regenerated thumbnails for \"Boardwalk\" (ID 757).\n    3/3 Regenerated thumbnails for \"Sunburst Over River\" (ID 756).\n    Success: Regenerated 3 of 3 images.\n\n    # Re-generate all thumbnails that have IDs between 1000 and 2000.\n    $ seq 1000 2000 | xargs wp media regenerate\n    Found 4 images to regenerate.\n    1/4 Regenerated thumbnails for \"Vertical Featured Image\" (ID 1027).\n    2/4 Regenerated thumbnails for \"Horizontal Featured Image\" (ID 1022).\n    3/4 Regenerated thumbnails for \"Unicorn Wallpaper\" (ID 1045).\n    4/4 Regenerated thumbnails for \"I Am Worth Loving Wallpaper\" (ID 1023).\n    Success: Regenerated 4 of 4 images.\n\n    # Re-generate only the thumbnails of \"large\" image size for all images.\n    $ wp media regenerate --image_size=large\n    Do you really want to regenerate the \"large\" image size for all images? [y/n] y\n    Found 3 images to regenerate.\n    1/3 Regenerated \"large\" thumbnail for \"Sydney Harbor Bridge\" (ID 760).\n    2/3 No \"large\" thumbnail regeneration needed for \"Boardwalk\" (ID 757).\n    3/3 Regenerated \"large\" thumbnail for \"Sunburst Over River\" (ID 756).\n    Success: Regenerated 3 of 3 images.\n\n\n\n### wp media image-size\n\nLists image sizes registered with WordPress.\n\n~~~\nwp media image-size [--fields=\u003cfields\u003e] [--format=\u003cformat\u003e]\n~~~\n\n**OPTIONS**\n\n\t[--fields=\u003cfields\u003e]\n\t\tLimit the output to specific fields. Defaults to all fields.\n\n\t[--format=\u003cformat\u003e]\n\t\tRender output in a specific format\n\t\t---\n\t\tdefault: table\n\t\toptions:\n\t\t  - table\n\t\t  - json\n\t\t  - csv\n\t\t  - yaml\n\t\t  - count\n\t\t---\n\n**AVAILABLE FIELDS**\n\nThese fields will be displayed by default for each image size:\n* name\n* width\n* height\n* crop\n* ratio\n\n**EXAMPLES**\n\n    # List all registered image sizes\n    $ wp media image-size\n    +---------------------------+-------+--------+-------+-------+\n    | name                      | width | height | crop  | ratio |\n    +---------------------------+-------+--------+-------+-------+\n    | full                      |       |        | N/A   | N/A   |\n    | twentyfourteen-full-width | 1038  | 576    | hard  | 173:96|\n    | large                     | 1024  | 1024   | soft  | N/A   |\n    | medium_large              | 768   | 0      | soft  | N/A   |\n    | medium                    | 300   | 300    | soft  | N/A   |\n    | thumbnail                 | 150   | 150    | hard  | 1:1   |\n    +---------------------------+-------+--------+-------+-------+\n\n## Installing\n\nThis package is included with WP-CLI itself, no additional installation necessary.\n\nTo install the latest version of this package over what's included in WP-CLI, run:\n\n    wp package install git@github.com:wp-cli/media-command.git\n\n## Contributing\n\nWe appreciate you taking the initiative to contribute to this project.\n\nContributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.\n\nFor a more thorough introduction, [check out WP-CLI's guide to contributing](https://make.wordpress.org/cli/handbook/contributing/). This package follows those policy and guidelines.\n\n### Reporting a bug\n\nThink you’ve found a bug? We’d love for you to help us get it fixed.\n\nBefore you create a new issue, you should [search existing issues](https://github.com/wp-cli/media-command/issues?q=label%3Abug%20) to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.\n\nOnce you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please [create a new issue](https://github.com/wp-cli/media-command/issues/new). Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, [review our bug report documentation](https://make.wordpress.org/cli/handbook/bug-reports/).\n\n### Creating a pull request\n\nWant to contribute a new feature? Please first [open a new issue](https://github.com/wp-cli/media-command/issues/new) to discuss whether the feature is a good fit for the project.\n\nOnce you've decided to commit the time to seeing your pull request through, [please follow our guidelines for creating a pull request](https://make.wordpress.org/cli/handbook/pull-requests/) to make sure it's a pleasant experience. See \"[Setting up](https://make.wordpress.org/cli/handbook/pull-requests/#setting-up)\" for details specific to working on this package locally.\n\n## Support\n\nGitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support\n\n\n*This README.md is generated dynamically from the project's codebase using `wp scaffold package-readme` ([doc](https://github.com/wp-cli/scaffold-package-command#wp-scaffold-package-readme)). To suggest changes, please submit a pull request against the corresponding part of the codebase.*\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-cli%2Fmedia-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwp-cli%2Fmedia-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-cli%2Fmedia-command/lists"}