How can I web scrape to get images from different websites using processing?

Hi! I’m trying to get images from reddit and load them into my processing sketch. How do I do this?

First, you need to write a small script to load an image. Here is a starter:

//===========================================================================
// GLOBAL VARIABLES:
PImage solar;

//===========================================================================
// PROCESSING DEFAULT FUNCTIONS:

void settings(){
  size(320,121);
}

void setup(){

  textAlign(CENTER,CENTER);
  rectMode(CENTER);
  
  fill(255);
  strokeWeight(2);
  noLoop();
  
  //SOURCE: https://en.wikipedia.org/wiki/File:Solar-System.pdf
  solar=loadImage("https://upload.wikimedia.org/wikipedia/commons/thumb/6/64/Solar-System.pdf/page1-320px-Solar-System.pdf.jpg");
}

void draw(){
  background(0);
  image(solar,0,0,width,height);
  
}

This script is helpful for debugging issues upfront when loading specific images. Can you load images directly (aka manually) from your source site?

After that, you can use loadStrings to load your target size, parse the image tags in the html content and extract the images.

Kf

This doesnt always work.

For example,
https://digimon.shadowsmith.com/img/koromon.jpg
or
https://www.google.de//images/branding/googlelogo/2x/googlelogo_color_272x92dp.png

dont give any images when substituted in the script but these images clearly exist.