Skip to content

Commit

Permalink
Show image, use spaceship operator
Browse files Browse the repository at this point in the history
* And move title.
  • Loading branch information
Inwerpsel committed Apr 27, 2022
1 parent 80cdfb5 commit 024dc17
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,36 +504,32 @@ function () {
$results = new WP_Query( $args );
$images = array_map( function ( $image_id ) {
$src = wp_get_attachment_image_src( $image_id, 'full' )[0];
$title = get_the_title( $image_id );
$size_check = curl_get_file_size( $src );
$size = $size_check <= 0 ? '' : formatBytes( $size_check );

return [
'id' => $image_id,
'src' => $src,
'title' => $title,
'size' => $size,
'size_bytes' =>$size_check,
'id' => $image_id,
'src' => $src,
'size' => $size,
'size_bytes' => $size_check,
];
}, $results->posts);
}, $results->posts );

uasort( $images, function ( $a, $b ) {
if ( $a['size_bytes'] === $b['size_bytes'] ) {
return 0;
}

return $a['size_bytes'] > $b['size_bytes'] ? -1 : 1;
} );
uasort(
$images,
fn( $a, $b ) => $b['size_bytes'] <=> $a['size_bytes']
);

echo "<h1>PNG Report</h1>";
echo '<table>';
foreach ( $images as $image ) {
$size = $image['size'];
$src = $image['size'];
$src = $image['src'];
$image_id = $image['id'];
$title = $image['title'];
$title = get_the_title( $image_id );
echo '<tr>';
echo "<td>size: $size</td>";
echo '<td>' . wp_get_attachment_image( $image_id ) . '</td>';
echo "<td style='text-align: right'>size: $size</td>";
echo "<td><a href=\"$src\">#$image_id ($title)</a></td>";

$image_posts = get_image_posts( $image_id );
Expand Down

0 comments on commit 024dc17

Please sign in to comment.