PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.21
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.21
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / includes / class-wpo-image-utils.php

class-wpo-image-utils.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.21, at includes/class-wpo-image-utils.php

75 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) die('Access denied.');
4
5 if (!class_exists('WPO_Image_Utils')) :
6
7 class WPO_Image_Utils {
8
9 /**
10 * Get image paths to resized attachment images.
11 *
12 * @param int $attachment_id
13 * @return array
14 */
15 public static function get_attachment_files($attachment_id) {
16 $attachment_images = array();
17 $upload_dir = wp_get_upload_dir();
18
19 // get sizes info from attachment meta data.
20 $meta = wp_get_attachment_metadata($attachment_id);
21 if (!is_array($meta) || !array_key_exists('sizes', $meta)) return $attachment_images;
22
23 $image_sizes = array_keys($meta['sizes']);
24
25 // build list of resized images.
26 foreach ($image_sizes as $size) {
27 $image = image_get_intermediate_size($attachment_id, $size);
28
29 if (is_array($image)) {
30 $file = trailingslashit($upload_dir['basedir']) . $image['path'];
31 if (is_file($file) && !in_array($file, $attachment_images)) {
32 $attachment_images[$size] = $file;
33 }
34 }
35 }
36
37 return $attachment_images;
38 }
39
40 /**
41 * Returns an array of allowed extensions
42 *
43 * @return array
44 */
45 public static function get_allowed_extensions() {
46 return array('gif', 'jpeg', 'jpg', 'png');
47 }
48
49 /**
50 * Returns given file extension
51 *
52 * @param string $file
53 *
54 * @return mixed
55 */
56 public static function get_extension($file) {
57 $file_type = wp_check_filetype($file);
58 return $file_type['ext'];
59 }
60
61 /**
62 * Tests if given extension is present in allowed extensions array
63 *
64 * @param string $ext Extension to check
65 * @param array $allowed_extensions Array of allowed extensions
66 *
67 * @return bool
68 */
69 public static function is_supported_extension($ext, $allowed_extensions) {
70 return in_array($ext, $allowed_extensions);
71 }
72 }
73
74 endif;
75