Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

Commit

Permalink
Updated Twitter controller for more flexibility (#16)
Browse files Browse the repository at this point in the history
* Updated Twitter controller for more flexibility with images and templates

* removing comment
  • Loading branch information
erikaheidi authored Nov 14, 2021
1 parent a0a0fa2 commit c537efd
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions app/Command/Generate/TwitterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public function handle(): int
$template_file = $this->getParam('template');
}

if (!is_file(Storage::root() . $template_file)) {
$this->getPrinter()->error("Template not found.");
return 1;
if (!is_file($template_file)) {
$template_file = Storage::root() . '/app/Resources/templates/' . $template_file;
if (!is_file($template_file)) {
$this->getPrinter()->error("Template not found.");
return 1;
}
}

$save_path = Storage::root() . 'latest_header.png';
$template = Template::create(Storage::root() . $template_file);
$template = Template::create($template_file);

$featured = [];
//build sources
Expand All @@ -42,7 +45,17 @@ public function handle(): int
*/
foreach ($template->placeholders as $key => $placeholder) {
if ($placeholder instanceof ImagePlaceholder and $placeholder->image) {
$placeholder->apply($template->getResource(), ['image_file' => Storage::root() . $placeholder->image]);
$resource_image = $placeholder->image;

if (filter_var($placeholder->image, FILTER_VALIDATE_URL)) {
$resource_image = Storage::downloadImage($placeholder->image);
}

if (!is_file($resource_image)) {
$resource_image = Storage::root() . $placeholder->image;
}

$placeholder->apply($template->getResource(), ['image_file' => $resource_image]);
continue;
}

Expand Down

0 comments on commit c537efd

Please sign in to comment.