we now provide images for all suffixes (0-3) -> simplify photo item body creation and provide width x height for any size

This commit is contained in:
Mario Vavti 2015-10-16 16:27:51 +02:00
parent 6f5f613d9f
commit b7408fa39e
2 changed files with 27 additions and 37 deletions

View File

@ -185,11 +185,11 @@ function photo_upload($channel, $observer, $args) {
if($args['description']) if($args['description'])
$p['description'] = $args['description']; $p['description'] = $args['description'];
$r1 = $ph->save($p); $r0 = $ph->save($p);
if(! $r1) $r0wxh = $ph->getWidth() . 'x' . $ph->getHeight();
if(! $r0)
$errors = true; $errors = true;
unset($p['os_storage']); unset($p['os_storage']);
unset($p['os_path']); unset($p['os_path']);
@ -197,18 +197,18 @@ function photo_upload($channel, $observer, $args) {
$ph->scaleImage(1024); $ph->scaleImage(1024);
$p['scale'] = 1; $p['scale'] = 1;
$r2 = $ph->save($p); $r1 = $ph->save($p);
$smallest = 1; $r1wxh = $ph->getWidth() . 'x' . $ph->getHeight();
if(! $r2) if(! $r1)
$errors = true; $errors = true;
if(($width > 640 || $height > 640) && (! $errors)) if(($width > 640 || $height > 640) && (! $errors))
$ph->scaleImage(640); $ph->scaleImage(640);
$p['scale'] = 2; $p['scale'] = 2;
$r3 = $ph->save($p); $r2 = $ph->save($p);
$smallest = 2; $r2wxh = $ph->getWidth() . 'x' . $ph->getHeight();
if(! $r3) if(! $r2)
$errors = true; $errors = true;
if(($width > 320 || $height > 320) && (! $errors)) if(($width > 320 || $height > 320) && (! $errors))
@ -216,7 +216,7 @@ function photo_upload($channel, $observer, $args) {
$p['scale'] = 3; $p['scale'] = 3;
$r3 = $ph->save($p); $r3 = $ph->save($p);
$smallest = 3; $r3wxh = $ph->getWidth() . 'x' . $ph->getHeight();
if(! $r3) if(! $r3)
$errors = true; $errors = true;
@ -231,12 +231,6 @@ function photo_upload($channel, $observer, $args) {
return $ret; return $ret;
} }
// This will be the width and height of the smallest representation
$width_x_height = $ph->getWidth() . 'x' . $ph->getHeight();
// Create item container
$item_hidden = (($visible) ? 0 : 1 ); $item_hidden = (($visible) ? 0 : 1 );
$lat = $lon = null; $lat = $lon = null;
@ -248,6 +242,19 @@ function photo_upload($channel, $observer, $args) {
} }
} }
$larger = feature_enabled($channel['channel_id'], 'large_photos');
if($larger) {
$tag = (($r1wxh) ? '[zmg=' . $r1wxh . ']' : '[zmg]');
$scale = 1;
}
else {
$tag = (($r2wxh) ? '[zmg=' . $r2wxh . ']' : '[zmg]');
$scale = 2;
}
// Create item container
if($args['item']) { if($args['item']) {
foreach($args['item'] as $i) { foreach($args['item'] as $i) {
@ -257,7 +264,7 @@ function photo_upload($channel, $observer, $args) {
if($item['mid'] === $item['parent_mid']) { if($item['mid'] === $item['parent_mid']) {
$item['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' $item['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']'
. $tag . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/zmg]' . $tag . z_root() . "/photo/{$photo_hash}-{$scale}.".$ph->getExt() . '[/zmg]'
. '[/zrl]'; . '[/zrl]';
if($item['author_xchan'] === $channel['channel_hash']) { if($item['author_xchan'] === $channel['channel_hash']) {
@ -319,26 +326,8 @@ function photo_upload($channel, $observer, $args) {
$arr['item_private'] = intval($acl->is_private()); $arr['item_private'] = intval($acl->is_private());
$arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid'];
// We should also put a width_x_height on large photos. Left as an exercise for
// devs looking for simple stuff to fix.
$larger = feature_enabled($channel['channel_id'], 'large_photos');
if($larger) {
$tag = '[zmg]';
if($r2)
$smallest = 1;
else
$smallest = 0;
}
else {
if ($width_x_height)
$tag = '[zmg=' . $width_x_height. ']';
else
$tag = '[zmg]';
}
$arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']'
. $tag . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/zmg]' . $tag . z_root() . "/photo/{$photo_hash}-{$scale}.".$ph->getExt() . '[/zmg]'
. '[/zrl]'; . '[/zrl]';
$result = item_store($arr); $result = item_store($arr);

View File

@ -78,7 +78,8 @@ code {
/* conv_item */ /* conv_item */
.wall-photo-item img { .wall-photo-item img {
width: 100%; width: 100% !important;
max-width: 100% !important;
} }
.wall-item-info { .wall-item-info {