Embed exported sizes into metadata; add support for fixed height/width exports
This commit is contained in:
56
convert.php
56
convert.php
@@ -84,12 +84,13 @@ The export option will accept values like:
|
|||||||
// manipulate
|
// manipulate
|
||||||
|
|
||||||
foreach ($photos as $i => $photo) {
|
foreach ($photos as $i => $photo) {
|
||||||
$output->write($photo['id'] . '...');
|
$output->write('<info>' . $photo['id'] . '</info>');
|
||||||
|
|
||||||
|
$photo['sizes'] = [];
|
||||||
|
|
||||||
// image exports
|
// image exports
|
||||||
if (0 < count($exports)) {
|
if (0 < count($exports)) {
|
||||||
$sourceJpg = $imagine->open($photo['path']);
|
$sourceJpg = $imagine->open($photo['path']);
|
||||||
$sourceSize = $sourceJpg->getSize();
|
|
||||||
|
|
||||||
if (isset($photo['exif']['Orientation'])) {
|
if (isset($photo['exif']['Orientation'])) {
|
||||||
switch ($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) {
|
foreach ($exports as $export) {
|
||||||
$output->write('<info>' . $export . '</info>...');
|
$output->write('<comment>' . $export . '</comment>');
|
||||||
|
|
||||||
if (false !== strpos($export, 'x')) {
|
if (false !== strpos($export, 'x')) {
|
||||||
list($w, $h) = explode('x', $export);
|
list($w, $h) = explode('x', $export);
|
||||||
@@ -141,14 +146,18 @@ The export option will accept values like:
|
|||||||
\Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND
|
\Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if ($sourceSize->getWidth() == max($sourceSize->getWidth(), $sourceSize->getHeight())) {
|
if ('w' == substr($export, -1)) {
|
||||||
$mx = (int) $export;
|
$mx = (int) $export;
|
||||||
$r = $mx / $sourceSize->getWidth();
|
$my = ($mx * $sourceSize->getHeight() ) / $sourceSize->getWidth();
|
||||||
$my = $sourceSize->getHeight() * $r;
|
} 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())) {
|
} elseif ($sourceSize->getHeight() == max($sourceSize->getWidth(), $sourceSize->getHeight())) {
|
||||||
$my = (int) $export;
|
$my = (int) $export;
|
||||||
$r = $my / $sourceSize->getHeight();
|
$mx = ($my * $sourceSize->getWidth()) / $sourceSize->getHeight();
|
||||||
$mx = $sourceSize->getWidth() * $r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$exportImage = $sourceJpg->thumbnail(
|
$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';
|
$exportPath = $assetPath . '/' . $photo['id'] . '~' . $export . '.jpg';
|
||||||
|
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
@@ -167,12 +185,14 @@ The export option will accept values like:
|
|||||||
touch($exportPath, $photo['date']->getTimestamp());
|
touch($exportPath, $photo['date']->getTimestamp());
|
||||||
|
|
||||||
$exportImage = null;
|
$exportImage = null;
|
||||||
|
|
||||||
|
$output->write('...');
|
||||||
}
|
}
|
||||||
|
|
||||||
$sourceJpg = null;
|
$sourceJpg = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->write('<info>mdown</info>...');
|
$output->write('<comment>markdown</comment>...');
|
||||||
|
|
||||||
$matter = [
|
$matter = [
|
||||||
'layout' => $layout,
|
'layout' => $layout,
|
||||||
@@ -205,8 +225,26 @@ The export option will accept values like:
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($photo['sizes']) {
|
||||||
|
$matter['sizes'] = $photo['sizes'];
|
||||||
|
}
|
||||||
|
|
||||||
ksort_recursive($matter);
|
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(
|
file_put_contents(
|
||||||
$renderPath . '/' . $photo['id'] . '.md',
|
$renderPath . '/' . $photo['id'] . '.md',
|
||||||
'---' . "\n" . Yaml::dump($matter, 4, 2) . '---' . "\n" . ((!empty($photo['comment'])) ? ($photo['comment'] . "\n") : '')
|
'---' . "\n" . Yaml::dump($matter, 4, 2) . '---' . "\n" . ((!empty($photo['comment'])) ? ($photo['comment'] . "\n") : '')
|
||||||
|
|||||||
Reference in New Issue
Block a user