For inctance, we need to convert all .gif to .jpg
Execute next commands in teminal
> cd /vaw/www/media/catalog/product/
> for i in $(find $(pwd) -name \*.gif -print); do convert $i $(echo $i.jpg | sed s/.gif//g); done
> rm -r cache/
Then, run these sql-statements in DB