Skip to content

Commit 602a683

Browse files
committed
Merge pull request #222 from ResponsiveImagesCG/dev
Version 3.0.0
2 parents de4a841 + c38194a commit 602a683

11 files changed

+1141
-708
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ php:
99
- 7.0
1010

1111
env:
12-
- WP_VERSION=latest WP_MULTISITE=0
13-
- WP_VERSION=latest WP_MULTISITE=1
12+
- WP_VERSION=trunk WP_MULTISITE=0
13+
- WP_VERSION=trunk WP_MULTISITE=1
14+
- WP_VERSION=4.3 WP_MULTISITE=0
15+
- WP_VERSION=4.3 WP_MULTISITE=1
1416
- WP_VERSION=4.2 WP_MULTISITE=0
1517
- WP_VERSION=4.2 WP_MULTISITE=1
1618
- WP_VERSION=4.1 WP_MULTISITE=0

bin/install-wp-tests.sh

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,56 @@ WP_VERSION=${5-latest}
1414
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
1515
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
1616

17+
download() {
18+
if [ `which curl` ]; then
19+
curl -s "$1" > "$2";
20+
elif [ `which wget` ]; then
21+
wget -nv -O "$2" "$1"
22+
fi
23+
}
24+
25+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
26+
WP_TESTS_TAG="tags/$WP_VERSION"
27+
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
28+
WP_TESTS_TAG="trunk"
29+
else
30+
# http serves a single offer, whereas https serves multiple. we only want one
31+
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
32+
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
33+
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
34+
if [[ -z "$LATEST_VERSION" ]]; then
35+
echo "Latest WordPress version could not be found"
36+
exit 1
37+
fi
38+
WP_TESTS_TAG="tags/$LATEST_VERSION"
39+
fi
40+
1741
set -ex
1842

1943
install_wp() {
44+
45+
if [ -d $WP_CORE_DIR ]; then
46+
return;
47+
fi
48+
2049
mkdir -p $WP_CORE_DIR
2150

22-
if [ $WP_VERSION == 'latest' ]; then
23-
local ARCHIVE_NAME='latest'
51+
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
52+
mkdir -p /tmp/wordpress-nightly
53+
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
54+
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
55+
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
2456
else
25-
local ARCHIVE_NAME="wordpress-$WP_VERSION"
57+
if [ $WP_VERSION == 'latest' ]; then
58+
local ARCHIVE_NAME='latest'
59+
else
60+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
61+
fi
62+
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
63+
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
2664
fi
2765

28-
wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/${ARCHIVE_NAME}.tar.gz
29-
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
30-
31-
wget -nv -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
66+
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
3267
}
3368

3469
install_test_suite() {
@@ -39,17 +74,24 @@ install_test_suite() {
3974
local ioption='-i'
4075
fi
4176

42-
# set up testing suite
43-
mkdir -p $WP_TESTS_DIR
77+
# set up testing suite if it doesn't yet exist
78+
if [ ! -d $WP_TESTS_DIR ]; then
79+
# set up testing suite
80+
mkdir -p $WP_TESTS_DIR
81+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
82+
fi
83+
4484
cd $WP_TESTS_DIR
45-
svn co --quiet https://develop.svn.wordpress.org/trunk/tests/phpunit/includes/
46-
47-
wget -nv -O wp-tests-config.php https://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php
48-
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" wp-tests-config.php
49-
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php
50-
sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php
51-
sed $ioption "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
52-
sed $ioption "s|localhost|${DB_HOST}|" wp-tests-config.php
85+
86+
if [ ! -f wp-tests-config.php ]; then
87+
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
88+
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
89+
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
90+
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
91+
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
92+
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
93+
fi
94+
5395
}
5496

5597
install_db() {

class-respimg.php

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* hacked up version of php-respimg <https://github.com/nwtn/php-respimg>
4+
* Hacked up version of php-respimg: https://github.com/nwtn/php-respimg
55
*
66
* @package wp-respimg
77
* @version 0.0.1
@@ -35,9 +35,10 @@ class Respimg extends Imagick {
3535
*
3636
* @access public
3737
*
38-
* @param integer $columns The number of columns in the output image. 0 = maintain aspect ratio based on $rows.
39-
* @param integer $rows The number of rows in the output image. 0 = maintain aspect ratio based on $columns.
40-
* @param bool $optim Whether you intend to perform optimization on the resulting image. Note that setting this to `true` doesn’t actually perform any optimization.
38+
* @param integer $columns The number of columns in the output image. 0 = maintain aspect ratio based on $rows.
39+
* @param integer $rows The number of rows in the output image. 0 = maintain aspect ratio based on $columns.
40+
* @param bool $optim Whether you intend to perform optimization on the resulting image.
41+
* Note that setting this to 'true' doesn't actually perform any optimization.
4142
*/
4243

4344
public function smartResize( $columns, $rows, $optim = false ) {
@@ -61,41 +62,41 @@ public function smartResize( $columns, $rows, $optim = false ) {
6162
if ( ! $optim ) {
6263
$this->stripImage();
6364
}
64-
6565
}
6666

67-
6867
/**
6968
* Changes the size of an image to the given dimensions and removes any associated profiles.
7069
*
7170
* `thumbnailImage` changes the size of an image to the given dimensions and
72-
* removes any associated profiles. The goal is to produce small low cost
71+
* removes any associated profiles. The goal is to produce small low cost
7372
* thumbnail images suited for display on the Web.
7473
*
7574
* With the original Imagick thumbnailImage implementation, there is no way to choose a
7675
* resampling filter. This class recreates Imagick’s C implementation and adds this
7776
* additional feature.
7877
*
79-
* Note: <https://github.com/mkoppanen/imagick/issues/90> has been filed for this issue.
78+
* Note: https://github.com/mkoppanen/imagick/issues/90 has been filed for this issue.
8079
*
8180
* @access public
8281
*
83-
* @param integer $columns The number of columns in the output image. 0 = maintain aspect ratio based on $rows.
84-
* @param integer $rows The number of rows in the output image. 0 = maintain aspect ratio based on $columns.
85-
* @param bool $bestfit Treat $columns and $rows as a bounding box in which to fit the image.
86-
* @param bool $fill Fill in the bounding box with the background colour.
87-
* @param integer $filter The resampling filter to use. Refer to the list of filter constants at <http://php.net/manual/en/imagick.constants.php>.
82+
* @param integer $columns The number of columns in the output image. 0 = maintain aspect ratio based on $rows.
83+
* @param integer $rows The number of rows in the output image. 0 = maintain aspect ratio based on $columns.
84+
* @param bool $bestfit Treat $columns and $rows as a bounding box in which to fit the image.
85+
* @param bool $fill Fill in the bounding box with the background colour.
86+
* @param integer $filter The resampling filter to use. Refer to the list of filter constants at <http://php.net/manual/en/imagick.constants.php>.
8887
*
89-
* @return bool Indicates whether the operation was performed successfully.
88+
* @return bool Indicates whether the operation was performed successfully.
9089
*/
9190

9291
public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false, $filter = Imagick::FILTER_TRIANGLE ) {
9392

94-
// sample factor; defined in original ImageMagick thumbnailImage function
95-
// the scale to which the image should be resized using the `sample` function
93+
/*
94+
* Sample factor; defined in original ImageMagick thumbnailImage function
95+
* the scale to which the image should be resized using the 'sample' function.
96+
*/
9697
$SampleFactor = 5;
9798

98-
// filter whitelist
99+
// Filter whitelist.
99100
$filters = array(
100101
Imagick::FILTER_POINT,
101102
Imagick::FILTER_BOX,
@@ -114,23 +115,23 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
114115
Imagick::FILTER_SINC
115116
);
116117

117-
// Parse parameters given to function
118+
// Parse parameters given to function.
118119
$columns = (double) $columns;
119120
$rows = (double) $rows;
120121
$bestfit = (bool) $bestfit;
121122
$fill = (bool) $fill;
122123

123-
// We can’t resize to (0,0)
124+
// We can’t resize to (0,0).
124125
if ( $rows < 1 && $columns < 1 ) {
125126
return false;
126127
}
127128

128-
// Set a default filter if an acceptable one wasn’t passed
129+
// Set a default filter if an acceptable one wasn’t passed.
129130
if ( ! in_array( $filter, $filters ) ) {
130131
$filter = Imagick::FILTER_TRIANGLE;
131132
}
132133

133-
// figure out the output width and height
134+
// Figure out the output width and height.
134135
$width = (double) $this->getImageWidth();
135136
$height = (double) $this->getImageHeight();
136137
$new_width = $columns;
@@ -144,8 +145,10 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
144145
$new_width = round( $y_factor * $width );
145146
}
146147

147-
// if bestfit is true, the new_width/new_height of the image will be different than
148-
// the columns/rows parameters; those will define a bounding box in which the image will be fit
148+
/*
149+
* If bestfit is true, the new_width/new_height of the image will be different than
150+
* the columns/rows parameters; those will define a bounding box in which the image will be fit.
151+
*/
149152
if ( $bestfit && $x_factor > $y_factor ) {
150153
$x_factor = $y_factor;
151154
$new_width = round( $y_factor * $width );
@@ -160,8 +163,10 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
160163
$new_height = 1;
161164
}
162165

163-
// if we’re resizing the image to more than about 1/3 it’s original size
164-
// then just use the resize function
166+
/*
167+
* If we’re resizing the image to more than about 1/3 it’s original size
168+
* then just use the resize function.
169+
*/
165170
if ( ( $x_factor * $y_factor ) > 0.1 ) {
166171
$this->resizeImage( $new_width, $new_height, $filter, 1 );
167172

@@ -215,8 +220,10 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
215220
$this->setImageProperty( 'Thumb::Document::Pages', '' );
216221
}
217222

218-
// In case user wants to fill use extent for it rather than creating a new canvas
219-
// …fill out the bounding box
223+
/*
224+
* In case user wants to fill use extent for it rather than creating a new canvas
225+
* fill out the bounding box.
226+
*/
220227
if ( $bestfit && $fill && ( $new_width != $columns || $new_height != $rows ) ) {
221228
$extent_x = 0;
222229
$extent_y = 0;
@@ -233,7 +240,5 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
233240
}
234241

235242
return true;
236-
237243
}
238-
239244
}

class-wp-image-editor-respimg.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' );
1212

1313
/**
14-
* WordPress Image Editor Class for Image Manipulation through Imagick PHP Module with php-respimg
14+
* WordPress Image Editor Class for Image Manipulation through Imagick PHP Module with php-respimg.
1515
*
1616
* @package wp-respimg
1717
* @uses WP_Image_Editor_Imagick Extends class
@@ -34,8 +34,11 @@ public function load() {
3434
return new WP_Error( 'error_loading_image', __('File doesn&#8217;t exist?'), $this->file );
3535
}
3636

37-
/** This filter is documented in wp-includes/class-wp-image-editor-imagick.php */
38-
// Even though Imagick uses less PHP memory than GD, set higher limit for users that have low PHP.ini limits
37+
/*
38+
* This filter is documented in wp-includes/class-wp-image-editor-imagick.php
39+
*
40+
* Even though Imagick uses less PHP memory than GD, set higher limit for users that have low PHP.ini limits.
41+
*/
3942
@ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );
4043

4144
try {
@@ -44,7 +47,7 @@ public function load() {
4447
if ( ! $this->image->valid() ) {
4548
return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file);
4649
}
47-
// Select the first frame to handle animated images properly
50+
// Select the first frame to handle animated images properly.
4851
if ( is_callable( array( $this->image, 'setIteratorIndex' ) ) ) {
4952
$this->image->setIteratorIndex(0);
5053
}
@@ -200,8 +203,10 @@ public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = nu
200203
$this->image->setImagePage( $src_w, $src_h, 0, 0);
201204

202205
if ( $dst_w || $dst_h ) {
203-
// If destination width/height isn't specified, use same as
204-
// width/height from source.
206+
/*
207+
* If destination width/height isn't specified, use same as
208+
* width/height from source.
209+
*/
205210
if ( ! $dst_w ) {
206211
$dst_w = $src_w;
207212
}
@@ -222,5 +227,4 @@ public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = nu
222227
}
223228
return $this->update_size();
224229
}
225-
226230
}

0 commit comments

Comments
 (0)