问题
I have more than 500 images in Sitecore Media Library each image size is more than 1MB. Currently we are displaying these images as thumbnails in webpage but it takes more time to load.
So I planned reduce the size to less than 50KB for thumbnails and which click the image it shows the original size image. So how can I programmatically clone all the 500 images and compress the size in Sitecore?
回答1:
Sitecore has builded solution for resize image due to the size of image will be smaller. You can use query string parameters to get smaller image, then sitecore will resize and cached image so it will do this only once. More information: http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2011/05/media-options-and-query-string-parameters-in-the-sitecore-aspnet-cms.aspx
You can always reduce size of image by image compression. If you save media files on disk you can iterate by anyone and use this tool: https://tinyjpg.com/.
If you saved media files in DB you can just get item by xpath how to: http://www.symsoftsolutions.com/Blog/List/Get-Media-Url-From-Sitecore, compress like above and save new item.
来源:https://stackoverflow.com/questions/37160764/clone-sitecore-media-library-image-folder