Save images from an URL out of the MySQL database and resize them | PHP, MySQL.
In the MySQL database which we use for a comparison site there are located a lot of products (in table ‘affiliSt_products1′). The images of the products (column ‘prodImageURL’ and ‘prodImageSmall’) are now located at the merchant site. So every time when a comparison is made, all images of the products are loaded from the sites of the merchants. We want to have this changed by saving the images to a local directory, resize them (large and small) and change the imagesURLs in the database.
Here are the requirements:
1. Download the images of all products from table ‘affiliSt_products1′, column ‘prodImageURL’. An image can be in GIF or in JPEG format.
2. Save them in the directory ‘/afbeeldingen/origineel’ and use the productname (column ‘prodName’) + productID of the merchant (column ‘merchantProdID’) as filename. Recplace spaces in the filename with ‘-‘. So for example a filename could be Van-der-valk-hotel-Assen-12345.jpg.
3. Resize the images in 2 formats, one which has a width of 180px and one which has a width of 250px. The image quality has to be adjustable.
4. Save the 180px images in the directory ‘/afbeeldingen/klein’ , save the 250px images in the directory ‘/afbeeldingen/groot’.
5. Change the old URLs of the images in the database to the new ones. Update the URLs of the 250px images in column ‘prodImageURL’ and the 180px images in ‘prodImageSmall’.
6. Every night all products are deleted and inserted again. So every night this project has to be run as a cronjob after the products are inserted. This means that I want to run this project directly from the PHP file you are going to create. So for example I want to run this from domain.com/cronjobs/update-images.php.
I have an example database online with all the products. Let me know if you need more information.
