diff --git a/convert.php b/convert.php
index 59f4796..45d77a1 100644
--- a/convert.php
+++ b/convert.php
@@ -84,12 +84,13 @@ The export option will accept values like:
// manipulate
foreach ($photos as $i => $photo) {
- $output->write($photo['id'] . '...');
+ $output->write('' . $photo['id'] . '');
+
+ $photo['sizes'] = [];
// image exports
if (0 < count($exports)) {
$sourceJpg = $imagine->open($photo['path']);
- $sourceSize = $sourceJpg->getSize();
if (isset($photo['exif']['Orientation'])) {
switch ($photo['exif']['Orientation']) {
@@ -130,8 +131,12 @@ The export option will accept values like:
}
}
+ $sourceSize = $sourceJpg->getSize();
+
+ $output->write('[' . $sourceSize->getWidth() . 'x' . $sourceSize->getHeight() . ']...');
+
foreach ($exports as $export) {
- $output->write('' . $export . '...');
+ $output->write('' . $export . '');
if (false !== strpos($export, 'x')) {
list($w, $h) = explode('x', $export);
@@ -141,14 +146,18 @@ The export option will accept values like:
\Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND
);
} else {
- if ($sourceSize->getWidth() == max($sourceSize->getWidth(), $sourceSize->getHeight())) {
+ if ('w' == substr($export, -1)) {
$mx = (int) $export;
- $r = $mx / $sourceSize->getWidth();
- $my = $sourceSize->getHeight() * $r;
+ $my = ($mx * $sourceSize->getHeight() ) / $sourceSize->getWidth();
+ } elseif ('h' == substr($export, -1)) {
+ $my = (int) $export;
+ $mx = ($my * $sourceSize->getWidth() ) / $sourceSize->getHeight();
+ } elseif ($sourceSize->getWidth() == max($sourceSize->getWidth(), $sourceSize->getHeight())) {
+ $mx = (int) $export;
+ $my = ($mx * $sourceSize->getHeight()) / $sourceSize->getWidth();
} elseif ($sourceSize->getHeight() == max($sourceSize->getWidth(), $sourceSize->getHeight())) {
$my = (int) $export;
- $r = $my / $sourceSize->getHeight();
- $mx = $sourceSize->getWidth() * $r;
+ $mx = ($my * $sourceSize->getWidth()) / $sourceSize->getHeight();
}
$exportImage = $sourceJpg->thumbnail(
@@ -157,6 +166,15 @@ The export option will accept values like:
);
}
+ $exportSize = $exportImage->getSize();
+
+ $photo['sizes'][$export] = [
+ 'width' => $exportSize->getWidth(),
+ 'height' => $exportSize->getHeight(),
+ ];
+
+ $output->write('[' . $exportSize->getWidth() . 'x' . $exportSize->getHeight() . ']');
+
$exportPath = $assetPath . '/' . $photo['id'] . '~' . $export . '.jpg';
file_put_contents(
@@ -167,12 +185,14 @@ The export option will accept values like:
touch($exportPath, $photo['date']->getTimestamp());
$exportImage = null;
+
+ $output->write('...');
}
$sourceJpg = null;
}
- $output->write('mdown...');
+ $output->write('markdown...');
$matter = [
'layout' => $layout,
@@ -205,8 +225,26 @@ The export option will accept values like:
];
}
+ if ($photo['sizes']) {
+ $matter['sizes'] = $photo['sizes'];
+ }
+
ksort_recursive($matter);
+ uasort(
+ $matter['sizes'],
+ function ($a, $b) {
+ $aa = $a['width'] * $a['height'];
+ $bb = $b['width'] * $b['height'];
+
+ if ($aa == $bb) {
+ return 0;
+ }
+
+ return ($aa > $bb) ? -1 : 1;
+ }
+ );
+
file_put_contents(
$renderPath . '/' . $photo['id'] . '.md',
'---' . "\n" . Yaml::dump($matter, 4, 2) . '---' . "\n" . ((!empty($photo['comment'])) ? ($photo['comment'] . "\n") : '')