Flying memes

Pics From The Past: ChatGPT and StableDiffusion powered facts of the day Photo Generation.

Wikimedia has a nice API which provides the facts of the day in JSON format, something like:


{
"text": "Named after Bikini Atoll, the site of the nuclear weapons test Operation Crossroads in the Marshall Islands, the modern bikini was introduced at a fashion show in Paris",
"year": 1946
}, {
...

We can take one of these events and ask ChatGPT APIs to generate the description of a black and white photo representing it, we can ask for composition details, camera and a couple of tags associated to the image. The prompt for this looks like:


$assistant = >>>PROMPT
You are a helpful assistant that given a description of an event describes in 
a sentence, for a generative AI, a black and white award winning photo take 
during that event, including an extremly brief description of the composition, 
and the exact name of camera and lenses used.
On a new line starting with '---', you'll also suggest 2 hashtags for the photo,
 avoiding too crude or inappropriate ones. 
PROMPT;

Passing the prompt above, alongside the description of the event returned by Wikimedia API, ChatGPT will return something like this:


The black and white award-winning photo captures the iconic moment as a model 
confidently struts down the runway in the first modern bikini, showcasing its 
daring design and challenging societal norms. Shot using a vintage Leica III 
camera and a 50mm lens.
---
#FashionRevolution #BreakingNorms

Finally we can pass the ChatGTP photo description to StableDiffusion APIs and obtain the actual image for the event. Before saving it I also do an extra optional step an add the description of the fact of the day on top of the image itself:


function writePromptToImagick($image, $prompt) {
  $draw = new ImagickDraw();
  $draw->setFillColor('#000000');
  $draw->setFont('Bookman-DemiItalic');
  $draw->setStrokeColor('#FFFFFF');
  $draw->setStrokeWidth(1);
  $draw->setStrokeAlpha(0.6);
  $draw->setGravity(Imagick::GRAVITY_NORTHWEST);
  $draw->setFontSize(20);
  $lineHeight = 23;
  $str = wordwrap($prompt, 80, "\n");
  $strArray = explode("\n",$str);
  $y = 30;
  foreach($strArray as $line) {
      $image->annotateImage($draw, 20, $y, 0, $line);
      $y += $lineHeight;
  }
}

// add a white 60% alpha rectangle to the top of the imagick object
function addWhiteRectangle($image, $prompt) {
  $y = 7 + (30 * count(explode("\n", wordwrap($prompt, 80, "\n"))));
  $draw = new ImagickDraw();
  $draw->setFillColor('#FFFFFF');
  $draw->setFillAlpha(0.6);
  $draw->rectangle(0, 0, 1024, $y);
  $image->drawImage($draw);
}

And here’s the resulting image:

I’ve created a dedicated Twitter account, PicsFromThePast where one of such pictures is posted every couple of hours. The ChatGPT-generated prompt is used to provide the ALT text for the Tweet.