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

Commit

Permalink
Merge pull request #9 from erikaheidi/gdaisy
Browse files Browse the repository at this point in the history
Refactored to use erikaheidi/gdaisy
  • Loading branch information
erikaheidi committed Jun 26, 2021
2 parents a650071 + 9e195a1 commit 546c717
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 216 deletions.
19 changes: 17 additions & 2 deletions app/Command/Generate/TwitterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace App\Command\Generate;

use App\ImageSource;
use App\Service\TwitterServiceProvider;
use App\Storage;
use App\Template;
use GDaisy\ImagePlaceholder;
use GDaisy\PlaceholderInterface;
use Minicli\Command\CommandController;

class TwitterController extends CommandController
Expand All @@ -27,13 +28,27 @@ public function handle(): int
$template = Template::create(Storage::root() . $template_file);

$featured = [];
//build sources
foreach ($template->sources as $key => $params) {
/** @var ImageSource $source */
$source = new $params['class'];
$featured = array_merge($featured, $source->getImageList($this->getApp(), $params['count']));
}

$template->build($featured);
//apply
/**
* @var string $key
* @var PlaceholderInterface $placeholder
*/
foreach ($template->placeholders as $key => $placeholder) {
if ($placeholder instanceof ImagePlaceholder and $placeholder->image) {
$placeholder->apply($template->getResource(), ['image_file' => $placeholder->image]);
continue;
}

$placeholder->apply($template->getResource(), $featured[$key]);
}

$template->write($save_path);
$this->getPrinter()->info("Finished generating cover at $save_path.");

Expand Down
3 changes: 2 additions & 1 deletion app/ImageSource/GhSponsorImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function getImageList(App $app, $limit = 5): array
$avatar = Storage::downloadImage($sponsor->avatarUrl);
$featured[self::$prefix . "$count"] = [
'screen_name' => $sponsor->login,
'avatar' => $avatar
'avatar' => $avatar,
'image_file' => $avatar
];

$count++;
Expand Down
3 changes: 2 additions & 1 deletion app/ImageSource/TwitterFollowerImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function getImageList(App $app, $limit = 5): array
$avatar = Storage::downloadImage($avatar_path);
$featured[self::$prefix . "$count"] = [
'screen_name' => $follower->screen_name,
'avatar' => $avatar
'avatar' => $avatar,
'image_file' => $avatar
];

$count++;
Expand Down
68 changes: 43 additions & 25 deletions app/Resources/templates/cover_basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,59 @@
},
"elements": {
"tw1": {
"pos_x": 486,
"pos_y": 272,
"width": 130,
"height": 130
"type": "image",
"properties": {
"pos_x": 486,
"pos_y": 272,
"width": 130,
"height": 130
}
},
"tw2": {
"pos_x": 670,
"pos_y": 270,
"width": 132,
"height": 132
"type": "image",
"properties": {
"pos_x": 670,
"pos_y": 270,
"width": 132,
"height": 132
}
},
"tw3": {
"pos_x": 859,
"pos_y": 270,
"width": 132,
"height": 132
"type": "image",
"properties": {
"pos_x": 859,
"pos_y": 270,
"width": 132,
"height": 132
}
},
"tw4": {
"pos_x": 1049,
"pos_y": 270,
"width": 132,
"height": 132
"type": "image",
"properties": {
"pos_x": 1049,
"pos_y": 270,
"width": 132,
"height": 132
}
},
"tw5": {
"pos_x": 1236,
"pos_y": 270,
"width": 130,
"height": 130
"type": "image",
"properties": {
"pos_x": 1236,
"pos_y": 270,
"width": 130,
"height": 130
}
},
"cover": {
"width": 1500,
"height": 500,
"pos_x": 0,
"pos_y": 0,
"image": "app/Resources/images/cover_basic.png"
"type": "image",
"properties": {
"width": 1500,
"height": 500,
"pos_x": 0,
"pos_y": 0,
"image": "app/Resources/images/cover_basic.png"
}
}
}
}
68 changes: 43 additions & 25 deletions app/Resources/templates/cover_colorful.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,59 @@
},
"elements": {
"tw1": {
"pos_x": 486,
"pos_y": 272,
"width": 130,
"height": 130
"type": "image",
"properties": {
"pos_x": 486,
"pos_y": 272,
"width": 130,
"height": 130
}
},
"tw2": {
"pos_x": 670,
"pos_y": 270,
"width": 132,
"height": 132
"type": "image",
"properties": {
"pos_x": 670,
"pos_y": 270,
"width": 132,
"height": 132
}
},
"tw3": {
"pos_x": 859,
"pos_y": 270,
"width": 132,
"height": 132
"type": "image",
"properties": {
"pos_x": 859,
"pos_y": 270,
"width": 132,
"height": 132
}
},
"tw4": {
"pos_x": 1049,
"pos_y": 270,
"width": 132,
"height": 132
"type": "image",
"properties": {
"pos_x": 1049,
"pos_y": 270,
"width": 132,
"height": 132
}
},
"tw5": {
"pos_x": 1236,
"pos_y": 270,
"width": 130,
"height": 130
"type": "image",
"properties": {
"pos_x": 1236,
"pos_y": 270,
"width": 130,
"height": 130
}
},
"cover": {
"width": 1500,
"height": 500,
"pos_x": 0,
"pos_y": 0,
"image": "app/Resources/images/cover_colorful.png"
"type": "image",
"properties": {
"width": 1500,
"height": 500,
"pos_x": 0,
"pos_y": 0,
"image": "app/Resources/images/cover_colorful.png"
}
}
}
}
68 changes: 43 additions & 25 deletions app/Resources/templates/cover_neon.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,59 @@
},
"elements": {
"tw1": {
"pos_x": 838,
"pos_y": 275,
"width": 98,
"height": 98
"type": "image",
"properties": {
"pos_x": 486,
"pos_y": 272,
"width": 130,
"height": 130
}
},
"tw2": {
"pos_x": 962,
"pos_y": 275,
"width": 98,
"height": 98
"type": "image",
"properties": {
"pos_x": 670,
"pos_y": 270,
"width": 132,
"height": 132
}
},
"tw3": {
"pos_x": 1087,
"pos_y": 275,
"width": 98,
"height": 98
"type": "image",
"properties": {
"pos_x": 859,
"pos_y": 270,
"width": 132,
"height": 132
}
},
"tw4": {
"pos_x": 1212,
"pos_y": 275,
"width": 98,
"height": 98
"type": "image",
"properties": {
"pos_x": 1049,
"pos_y": 270,
"width": 132,
"height": 132
}
},
"tw5": {
"pos_x": 1338,
"pos_y": 275,
"width": 98,
"height": 98
"type": "image",
"properties": {
"pos_x": 1236,
"pos_y": 270,
"width": 130,
"height": 130
}
},
"cover": {
"width": 1500,
"height": 500,
"pos_x": 0,
"pos_y": 0,
"image": "app/Resources/images/cover_neon.png"
"type": "image",
"properties": {
"width": 1500,
"height": 500,
"pos_x": 0,
"pos_y": 0,
"image": "app/Resources/images/cover_neon.png"
}
}
}
}
Loading

0 comments on commit 546c717

Please sign in to comment.