更改设置 > 媒体 > 缩略图大小后,我有没有一种简单的方法可以重新生成图像缩略图?
我知道有这方面的插件,但我有超过 30k 的图像。即使是 ajax 也需要永远完成。
我在 VPS CentOS 上,所以我可以运行 iconv、ffmpegthumbs 等东西,所以我有办法从 bash 完成这项任务吗?
更新 1。
这是我为完成这项工作而编写的脚本。我需要在包含图像的文件夹中才能运行它。
#! /bin/bash
# Copyright Synvi Group (http://www.synvigroup.com)
# Custom script to generate wordpress thumbnails for smokingd
# Dependencies: Imagemagick, rename, coreutils
echo Checking if sgthumbs already exists...
rm -rf sgthumb &
wait
echo Checking if list file already exists...
rm -f list &
wait
echo Generate list of files...
ls -1 --file-type | grep -v -e -[0-9][0-9][0-9]x[0-9][0-9][0-9] | grep -v -e -[0-9][0-9][0-9][0-9]x[0-9][0-9][0-9] | grep -v -e -[0-9][0-9][0-9]x[0-9][0-9][0-9][0-9] | grep -v -e -[0-9][0-9][0-9][0-9]x[0-9][0-9][0-9][0-9] | grep -v -e -[0-9][0-9][0-9]x[0-9][0-9] | grep -v -e -[0-9][0-9]x[0-9][0-9][0-9] | grep -v -e -[0-9][0-9]x[0-9][0-9] > list &
wait
echo Create sgthumb directory...
mkdir sgthumb &
wait
echo Copying files...
xargs -a list cp -t sgthumb/ &
wait
cd sgthumb
echo Generating thumbnails...
echo Processing jpg files..
mogrify -resize '610x200^' -gravity center -crop 610x200+0+0 +repage *.jpg &
wait
echo Processing png files..
mogrify -resize '610x200^' -gravity center -crop 610x200+0+0 +repage *.png &
wait
echo Appending the new size to filenames...
rename .jpg -610x200.jpg *.jpg &
wait
rename .png -610x200.png *.png &
wait
echo Fixing permissions...
chown smokingd:smokingd *
wait
chmod 777 *
wait
echo Moving thumbnails to main directory...
cp -p *.jpg ../
wait
cp -p *.png ../
wait
echo Cleaning up..
cd ..
wait
rm -rf sgthumb
wait
rm list
wait
echo Done!
其中 USER 是拥有文件的用户,PERMISSIONS 是文件的正确用户。
现在我需要更新数据库,以便旧帖子使用新的缩略图。旧帖子使用 150x150 的缩略图,并且使用的缩略图在其名称后附加了 -150x150。
更新 2。
以下查询运行良好:
UPDATE wp_postmeta SET meta_value = REPLACE (
meta_value,
'-150x150.jpg";s:5:"width";s:3:"150";s:6:"height";s:3:"150";}',
'-610x200.jpg";s:5:"width";s:3:"610";s:6:"height";s:3:"200";}');
假设原始缩略图大小为 150x150,新大小为 610x200。