#!/usr/bin/env php user->username . '.jpg'; $imageOutPath = implode(DIRECTORY_SEPARATOR, [$siteDir, "static/images/blog-cover-images", $imageOutName]); file_put_contents($imageOutPath, $imageContent); // Write out blogpost $hyphenVersion = str_replace('.', '-', trim($version)); $postMdName = "bookstack-release-{$hyphenVersion}.md"; $postMdOutPath = implode(DIRECTORY_SEPARATOR, [$siteDir, "content/blog", $postMdName]); $postMdContent = getPostMarkdown(); file_put_contents($postMdOutPath, $postMdContent); output("Done, Post created at {$postMdOutPath}"); function unsplashGet(string $id, string $unsplashKey) { $json = file_get_contents("https://api.unsplash.com/photos/{$id}?client_id={$unsplashKey}"); return json_decode($json); } function getImageContent($unsplashImage, int $width, int $height, int $quality) { $url = $unsplashImage->urls->raw; $url .= "&fm=jpg&w={$width}&h={$height}&fit=crop&q={$quality}&crop=focalpoint,center"; return file_get_contents($url); } function getPostMarkdown() { global $image, $imageContent, $version, $hyphenVersion, $imageOutName; $date = str_replace('+00:00', 'Z', date('c')); $content = <<Header Image Credits: Photo by {$image->user->name} on Unsplash POSTCONTENT; return $content; } function error($text) { echo $text . "\n"; exit(1); } function output($text) { echo $text . "\n"; } function read($question): string { $response = readline($question); if (!$response) { error("Failed to respond to question (" . $question . ")"); } return $response; }