Category Image – How to Change from .png to .jpg

categoryimage

I have several hundreds of category Images containing a .png extension. But I want to convert that images to .jpg (outside of Magento and not part of that question) and then reupload them to media/catalog/category and tell Magento to use the new .jpg extension for all .png Category Images. Including Thumbnail Image and Image field.

I found the quite similar Question Migrating All Product Images in Magento from PNGs to JPEGs but the difference is that I want to change Category Images and not Product Images.

Can someone tell me how to change that script or a different approach, please? Updating all Categories in the backend manually would take to much time.

Best Answer

Since this is a one time change you may wish to consider taking a SQL approach. This will be quicker, and, if you backup your database before hand, you can do this safely.

Your images for the categories are held in catalog_category_entity_varchar table however you did not say whether these are the main images or the thumbnails. Therefore have a quick search of the table to find out:

SELECT * FROM  `catalog_category_entity_varchar` WHERE  `value` LIKE  '%.png%';

This should return images that you know. Look at the value for attribute_id. This could be something like '45'.

Now you want to run an update, replacing xx with your attribute_id:

UPDATE `catalog_category_entity_varchar` SET `value` = REPLACE(`value`, '.png', '.jpg') WHERE `attribute_id`=xx;

If you are not happy with updating the database directly in a few minutes you could write a Magento module, iterate on the categories and update the image accordingly. However, for a one off the sql approach should work out nicely.

Related Topic