1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* FooGallery Thumbnail Resizing class |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
if ( !class_exists( 'FooGallery_Thumbnails' ) ) { |
7
|
|
|
|
8
|
|
|
class FooGallery_Thumbnails { |
9
|
|
|
|
10
|
|
|
function __construct() { |
11
|
|
|
//generate thumbs using WPThumb |
12
|
|
|
add_filter( 'foogallery_attachment_resize_thumbnail', array( $this, 'resize' ), 10, 3 ); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
function resize( $original_image_src, $args, $thumbnail_object ) { |
16
|
|
|
|
17
|
|
|
$arg_defaults = array( |
18
|
|
|
'width' => 0, |
19
|
|
|
'height' => 0, |
20
|
|
|
'crop' => true, |
21
|
|
|
'jpeg_quality' => foogallery_thumbnail_jpeg_quality(), |
22
|
|
|
'thumb_resize_animations' => foogallery_get_setting( 'thumb_resize_animations' ) |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
$args = wp_parse_args( $args, $arg_defaults ); |
26
|
|
|
|
27
|
|
|
if ( 'on' === foogallery_get_setting( 'use_original_thumbs' ) ) { |
28
|
|
|
$width = (int)$args['width']; |
29
|
|
|
$height = (int)$args['height']; |
30
|
|
|
$crop = (bool)$args['crop']; |
31
|
|
|
|
32
|
|
|
//check if we are trying to get back the default thumbnail that we already have |
33
|
|
|
if ( $thumbnail_object->ID > 0 && $width == get_option( 'thumbnail_size_w' ) && $height == get_option( 'thumbnail_size_h' ) && $crop == get_option( 'thumbnail_crop' ) ) { |
34
|
|
|
$thumbnail_attributes = wp_get_attachment_image_src( $thumbnail_object->ID ); |
35
|
|
|
|
36
|
|
|
return $thumbnail_attributes[0]; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if ( $thumbnail_object->ID > 0 ) { |
41
|
|
|
$crop_from_position = get_post_meta( $thumbnail_object->ID, 'wpthumb_crop_pos', true ); |
42
|
|
|
|
43
|
|
|
if ( !empty( $crop_from_position ) ) { |
44
|
|
|
$args['crop_from_position'] = $crop_from_position; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return wpthumb( $original_image_src, $args ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function run_tests() { |
|
|
|
|
52
|
|
|
$test_image_url = FOOGALLERY_URL . '/assets/test_thumb_1.jpg'; |
53
|
|
|
$thumb_width = get_option( 'thumbnail_size_w' ); |
54
|
|
|
$thumb_height = get_option( 'thumbnail_size_h' ); |
55
|
|
|
|
56
|
|
|
$test1_args = array( |
57
|
|
|
'width' => 20, |
58
|
|
|
'height' => 20, |
59
|
|
|
'crop' => true, |
60
|
|
|
'jpeg_quality' => foogallery_thumbnail_jpeg_quality() |
61
|
|
|
); |
62
|
|
|
$thumb1 = new WP_Thumb( $test_image_url, $test1_args ); |
63
|
|
|
$results[] = array( |
|
|
|
|
64
|
|
|
'thumb' => $thumb1->returnImage(), |
65
|
|
|
'error' => $thumb1->error(), |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$test2_args = array( |
69
|
|
|
'width' => 50, |
70
|
|
|
'height' => 80, |
71
|
|
|
'crop' => true, |
72
|
|
|
'crop_from_position' => 'right,center', |
73
|
|
|
'jpeg_quality' => foogallery_thumbnail_jpeg_quality() |
74
|
|
|
); |
75
|
|
|
$thumb2 = new WP_Thumb( $test_image_url, $test2_args ); |
76
|
|
|
$results[] = array( |
77
|
|
|
'thumb' => $thumb2->returnImage(), |
78
|
|
|
'error' => $thumb2->error(), |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$test3_args = array( |
82
|
|
|
'width' => $thumb_width, |
83
|
|
|
'height' => $thumb_height, |
84
|
|
|
'crop' => true, |
85
|
|
|
'jpeg_quality' => foogallery_thumbnail_jpeg_quality() |
86
|
|
|
); |
87
|
|
|
$thumb3 = new WP_Thumb( $test_image_url, $test3_args ); |
88
|
|
|
$results[] = array( |
89
|
|
|
'thumb' => $thumb3->returnImage(), |
90
|
|
|
'error' => $thumb3->error(), |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
return $results; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.