From our sponsor: Ready to show your plugin skills? Enter the Penpot Plugins Contest (Nov 15-Dec 15) to win cash prizes!
I was wondering how to get images from a site the same way like Digg or Facebook do, where it is only necessary to provide a link, and images get automatically uploaded to your server and resized. So, I decided to create a script that does exactly that and share it here.
This PHP script uses two php classes that I found on the web. One of them I have already used before in the “jQuery Image Cropper with Uploader” and the “Dynamic jQuery Image Gallery with Uploader“, the class.upload from verot . The other is a PHP html DOM Parser that can be found here.
In order to make this work, I had to change some few lines of code in verot’s class, so that URLs can be used to get images. The DOM Parser is untouched. I also created a file (index.php) where both scripts are called. I first parse the URL, search for images and pass the url of the image to the class.upload script, which then uploads the image to a local directory (images/) and resizes it. In this script, the image size is changed to a width of 150 pixels but the ratio is kept. However, you can change these values and configure it the way you want. Take a look at the documentation of the class.upload so that you know what you can change. Also, you can specify how many images you want to save / display per request.
Tiny break: 📬 Want to stay up to date with frontend and trends in web design? Subscribe and get our Collective newsletter twice a tweek.
For the demo (not available anymore, sorry!) which has this blog as “target”, I have configured that only a restricted amount of images are saved and shown. Besides, you might notice that sometimes it displays more images than other times. This is caused by the limited amount of memory configured in the php.ini file (memory_limit), so you might wanna change this value to a proper one if you want to use this script. Again, on verot’s web site, in the forums, there are some good calculations giving an idea of a suitable value.
Pingback: URL Image Getter/Uploader/Resizer | Codrops Search Engine Marketing
Pingback: uberVU - social comments
Pingback: Most Tweeted Articles by E-Commerce Experts
Hi,
Your demo doesnt work 🙁
Thanks James. There’s seems to be a problem since you visited the page! What have you done? Just joking, I will take a look and fix it soon.
Cheers
Haha! Working perfectly now, what an awesome script!
is this works for wordpress self host blog..?