Last active
February 6, 2019 14:12
-
-
Save yratof/16f43edc9d1d9476211e5681fbae90ed to your computer and use it in GitHub Desktop.
PNG JPG -> Wordpress remove all media generated by wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install ImageMagik
brew install imagemagik
then you can run all the commands above