Skip to content

Instantly share code, notes, and snippets.

@yratof
Last active February 6, 2019 14:12
Show Gist options
  • Save yratof/16f43edc9d1d9476211e5681fbae90ed to your computer and use it in GitHub Desktop.
Save yratof/16f43edc9d1d9476211e5681fbae90ed to your computer and use it in GitHub Desktop.
PNG JPG -> Wordpress remove all media generated by wordpress
# Go to your uploads folder
cd /wp-content/uploads
# Remove all images that wordpress created
find -E . -type f -iregex '.*[0-9]{2,3}x[0-9]{2,3}.*\.(jpg|jpeg|png|eps|gif)' -exec rm {} \;
# ZIP all original images incase things go wrong on this next bit
find . -type f | egrep -vi '.*[0-9]{2,3}x[0-9]{2,3}.*\.(jpg|jpeg|png|eps|gif)' | zip images.zip -@
# Convert what is left from png to jpg with white in place of transparency
find . -name "*.png" -exec mogrify -background white -flatten -format jpg {} \;
# Remove all Transparent pngs to leave only jpg
find -E . -type f -iregex '.*\.(png)' -exec rm {} \;
# SQL Query to rename all png to jpg
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, ".png", ".jpg") WHERE meta_key = '_wp_attached_file' AND meta_value like '%.png'
@yratof
Copy link
Author

yratof commented Jan 17, 2018

Install ImageMagik brew install imagemagik then you can run all the commands above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment