PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.5
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.5
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / functions / formatting.php

formatting.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.5, at inc/functions/formatting.php

47 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
3
4 /**
5 * Round UP to nearest half integer
6 *
7 * @since 1.0
8 * @source http://stackoverflow.com/a/13526408
9 *
10 * @param int $number The number to round up
11 * @return int $number The formatted number
12 */
13 function imagify_round_half_five( $number ) {
14 $number = strval( $number );
15 $number = explode( '.', $number );
16
17 if ( ! isset( $number[1] ) ) {
18 return $number[0];
19 }
20
21 $decimal = floatval( '0.' . substr( $number[1], 0 , 2 ) ); // cut only 2 number
22 if ( $decimal > 0 ) {
23 if( $decimal <= 0.5 ) {
24 return floatval( $number[0] ) + 0.5;
25 } elseif ( $decimal > 0.5 && $decimal <= 0.99 ) {
26 return floatval( $number[0]) + 1;
27 }
28 } else {
29 return floatval( $number );
30 }
31 }
32
33 /**
34 * Get the Imagify attachment class name depending to a context
35 *
36 * @since 1.5
37 * @source Jonathan Buttigieg
38 *
39 * @param string $context The context to determine the class name
40 * @return string $class_name The Imagify attachment class name
41 */
42 function get_imagify_attachment_class_name( $context = 'wp' ) {
43 $class_name = 'Imagify_';
44 $class_name .= 'wp' !== $context ? $context . '_Attachment' : 'Attachment';
45
46 return $class_name;
47 }