I ended up with my own dog breed/image API content in 10 minutes & you can have it too!

I recently had to build a sample project for a programming tutorial I will be giving. And I thought to myself, what better way to make the work fun but to build the sample project around cute dog images?

I wanted to be able to show cute dog pictures of each dog breed. I thought of different ways of getting the dog breeds. I considered scraping dog breed lists from wikipedia or another dog site with breed lists. But taking 30 minutes to an hour to write a scraping script tailored to the site layout to gather the dog breeds and corresponding image URLs just seemed like overkill. And, it didn’t help that wikipedia doesn’t have the cutest dog pictures. That means I would have had to manually curate cute dog pictures… Gross, manual curation in the age of Artificial Intelligence? Not for me. There had to be a better way.

Turns out there was a dog breed/image api project! Once I found it, it felt like there was no wrong in the world. I mean, what matters when a dog api exists? But this would have meant that I’d have to add a networking layer to my sample app when my tutorial would not include networking, not good! It also meant that I’d be dynamically fetching images for a sample app that could be used by kids… really not good! New images could be NSFW and definitely not safe for kids. Interesting to note that there was a Reddit about a dog image api which does not guarantee that the returned image is a dog… Definitely not safe either! Seemed like more work with more risk, not a great combination. I had also seen one breed/image that seemed offensive so I wasn’t eager to promote that API.

Then it hit me: why not two birds with one stone and have my own dog image api content? The dog breed list endpoint always returned an identical list and the image call URL for the corresponding breed images had a fixed structure based on the breed name. The content had no copyright claims, so I could write a simple PHP script to get a starting point for my own breed dog images done in simple steps. With this I could control the image quality and safety. Here is a similar updated PHP script to get the images from me:

1: Have the breed list.

$breeds = array(“affenpinscher”, “airedale”, “akita”, “appenzeller”, “basenji”, “beagle”, “bluetick”, “borzoi”, “bouvier”, “boxer”, “brabancon”, “briard”, “bulldog”, “bullterrier”, “cairn”, “chihuahua”, “chow”, “clumber”, “collie”, “coonhound”, “corgi”, “dachshund”, “dane”, “deerhound”, “dhole”, “dingo”, “doberman”, “elkhound”, “entlebucher”, “eskimo”, “germanshepherd”, “greyhound”, “groenendael”, “hound”, “husky”, “keeshond”, “kelpie”, “komondor”, “kuvasz”, “labrador”, “leonberg”, “lhasa”, “malamute”, “malinois”, “maltese”, “mastiff”, “mexicanhairless”, “mountain”, “newfoundland”, “otterhound”, “papillon”, “pekinese”, “pembroke”, “pinscher”, “pointer”, “pomeranian”, “poodle”, “pug”, “pyrenees”, “redbone”, “retriever”, “ridgeback”, “rottweiler”, “saluki”, “samoyed”, “schipperke”, “schnauzer”, “setter”, “sheepdog”, “shiba”, “shihtzu”, “spaniel”, “springer”, “stbernard”, “terrier”, “vizsla”, “weimaraner”, “whippet”, “wolfhound”);

2. Loop through the list & download the breed image to it’s corresponding folder. I had to parse through JSON and that fun stuff but you don’t :

for ($a=0;$a < sizeof($breeds);$a++){
if (!file_exists($breeds[$a])) {
mkdir($breeds[$a], 0777, true);
downloadFile(“https://www.StockMarketSensei.net/api/puppies/".$breeds[$a].’/’.$breeds[$a].’.jpg’, $breeds[$a].’/’.$breeds[$a].’.jpg’);
//Function to download file
function downloadFile($url, $path)
$newfname = $path;
$file = fopen ($url, ‘rb’);
if ($file) {
$newf = fopen ($newfname, ‘wb’);
if ($newf) {
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
if ($file) {
if ($newf) {

Of course, an equivalent script in any language would do.

3. You now have your own safe set of dog breed images to start with and build something cool, celebrate!

Key Lesson: It never hurts to think through better solutions before implementation even when you have one that you know would work.

My recent article on the threat of open A.I was a bit too scary, so I felt I needed to write a “fluff piece” to even it out. In a follow up post, I’ll show how to use these images to do something really fun with deep learning and computer vision!