Audio
1 day ago
Video
1 day ago
AttachmentMetaData.php
1 day ago
AttachmentUrl.php
1 day ago
AudioPlayer.php
1 day ago
AvailableSizes.php
1 day ago
Dimensions.php
1 day ago
Download.php
1 day ago
ExifData.php
1 day ago
FileLinkToUrl.php
1 day ago
FileName.php
1 day ago
FileSize.php
1 day ago
Link.php
1 day ago
NestedAttachmentMetaData.php
1 day ago
NumberFormat.php
1 day ago
PostMimeType.php
1 day ago
PreviewViewLink.php
1 day ago
VideoEmbed.php
1 day ago
Dimensions.php
34 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter\Media; |
| 6 | |
| 7 | use AC\Exception\ValueNotFoundException; |
| 8 | use AC\Formatter; |
| 9 | use AC\Helper; |
| 10 | use AC\Type\Value; |
| 11 | |
| 12 | class Dimensions implements Formatter |
| 13 | { |
| 14 | public function format(Value $value): Value |
| 15 | { |
| 16 | $meta = get_post_meta($value->get_id(), '_wp_attachment_metadata', true); |
| 17 | |
| 18 | if (empty($meta['width']) || empty($meta['height'])) { |
| 19 | throw new ValueNotFoundException(); |
| 20 | } |
| 21 | |
| 22 | $label = $meta['width'] . ' × ' . $meta['height']; |
| 23 | $tooltip = sprintf(__('Width : %s px', 'codepress-admin-columns'), $meta['width']) . "<br/>\n" . sprintf( |
| 24 | __('Height : %s px', 'codepress-admin-columns'), |
| 25 | $meta['height'] |
| 26 | ); |
| 27 | |
| 28 | return $value->with_value( |
| 29 | Helper\Html::create()->tooltip($label, $tooltip) |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | } |
| 34 |