'A picture is worth a thousand words', a famous adage. Images plays an important role in elaborating the contents. But at times there may transpire a situation where these images has to be saved from a remote site and then upload them into the corresponding content. If the images reaches a out bound limit, it becomes infeasible to have a endeavour. At such a instance the best approach is to programmatically save the images in your local system.
At a stretch the images cannot be saved easily into the local system, but can be done with a step of two. There are many other means by which this task can be achieved, but I prefer DOMDocument to other methods. The DOMDocument has the ability to scrape the contents of the page and get the Image tags. Once the image tags are obtained, with the help of the attributes the image source can also be gathered. file_save_data() saves the images from their corresponding source into the local system.
The below piece of code is taken from a successful implementation of this task. The below function can be called in the corresponding node's image field. In my case I retried the main images by making a check against the size of the image. If all the images has to be saved in your case, this check can be removed.
The saved images can be viewed in /sites/default/files/images.