Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tevko/wp-tevko-responsive-images
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: ResponsiveImagesCG/wp-tevko-responsive-images
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: dev
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.

Commits on Nov 6, 2014

  1. Copy the full SHA
    f15d897 View commit details
  2. Copy the full SHA
    70897ed View commit details
  3. a few minor fixes

    tevko committed Nov 6, 2014
    Copy the full SHA
    73734a0 View commit details
  4. Copy the full SHA
    5bd03ee View commit details
  5. Copy the full SHA
    8c06174 View commit details

Commits on Nov 7, 2014

  1. minor syntax edit

    tevko committed Nov 7, 2014
    Copy the full SHA
    01863fc View commit details
  2. add some comment clarification

    tevko committed Nov 7, 2014
    Copy the full SHA
    1caa1f6 View commit details

Commits on Nov 28, 2014

  1. Copy the full SHA
    9e49b77 View commit details
  2. changelog adjustments

    tevko committed Nov 28, 2014
    Copy the full SHA
    7f2c2ca View commit details

Commits on Dec 7, 2014

  1. Copy the full SHA
    370a5c2 View commit details

Commits on Dec 17, 2014

  1. Update wp-tevko-responsive-images.php

    Fixing error when I tried to activate the plugin:
    `Parse error: syntax error, unexpected '[' in /srv/www/vhosts/wptest/wp-content/plugins/respimg/wp-tevko-responsive-images.php on line 52`
    Function array dereferencing is unsupported in PHP 5.3 but was [added in 5.4](http://php.net/manual/en/migration54.new-features.php).
    Since WordPress only requires [PHP version 5.2.4 or greater](https://wordpress.org/about/requirements/)  other people might try to use the plugin using older versions of PHP.
    mdmcginn committed Dec 17, 2014
    Copy the full SHA
    84b5521 View commit details

Commits on Dec 18, 2014

  1. Disable the image size constraint applied to images in the editor.

    WordPress prevents images from overflowing the editor by automatically constraining them to $content_width (or 500px). We don’t want that in this case, so we’ll set the constrained size arbitrarily high.
    ryelle committed Dec 18, 2014
    Copy the full SHA
    eb81d47 View commit details
  2. Merge pull request #6 from ryelle/master

    Incorrect width attributes in srcset URLs
    tevko committed Dec 18, 2014
    Copy the full SHA
    2c59c5e View commit details
  3. Update wp-tevko-responsive-images.php

    Removed semicolon on line 54.
    mdmcginn committed Dec 18, 2014
    Copy the full SHA
    ab2b93b View commit details
  4. Update wp-tevko-responsive-images.php

    $origSrc isn't being used except to define $origWidth, so I didn't redeclare it as $origSrc[0]
    mdmcginn committed Dec 18, 2014
    Copy the full SHA
    ec2eebd View commit details

Commits on Dec 19, 2014

  1. Merge remote-tracking branch 'upstream/master'

    Conflicts:
    	wp-tevko-responsive-images.php
    mdmcginn committed Dec 19, 2014
    Copy the full SHA
    0eeab73 View commit details
  2. Changed wordpress to WordPress

    mdmcginn committed Dec 19, 2014
    Copy the full SHA
    aa912ca View commit details

Commits on Dec 29, 2014

  1. Copy the full SHA
    89a4526 View commit details
  2. Merge pull request #5 from mdmcginn/master

    Update wp-tevko-responsive-images.php
    tevko committed Dec 29, 2014
    Copy the full SHA
    df869ac View commit details
  3. Copy the full SHA
    6ed5275 View commit details

Commits on Dec 30, 2014

  1. rework get_src_sizes to allow the user to choose what image sizes the…

    …y need
    Brandon Lavigne authored and Brandon Lavigne committed Dec 30, 2014
    Copy the full SHA
    0b5b539 View commit details
  2. remove commented out company function

    Brandon Lavigne authored and Brandon Lavigne committed Dec 30, 2014
    Copy the full SHA
    bf95da4 View commit details
  3. Merge pull request #8 from drrobotnik/pr

    Pr
    tevko committed Dec 30, 2014
    Copy the full SHA
    f18d4e9 View commit details
  4. another test and readme update

    tevko committed Dec 30, 2014
    Copy the full SHA
    0a26d65 View commit details
  5. readme formatting

    tevko committed Dec 30, 2014
    Copy the full SHA
    c4af218 View commit details
  6. third times the charm

    tevko committed Dec 30, 2014
    Copy the full SHA
    df3ae78 View commit details

Commits on Dec 31, 2014

  1. remove cropped images from the list used in srcset

    Joe McGill committed Dec 31, 2014
    Copy the full SHA
    1718c99 View commit details
  2. Merge pull request #9 from joemcgill/avoid_crops

    Keep srcset from using hard cropped images
    tevko committed Dec 31, 2014
    Copy the full SHA
    b803a44 View commit details
  3. Better handling of cropped images

    Joe McGill committed Dec 31, 2014
    Copy the full SHA
    7e130c1 View commit details
  4. Merge pull request #11 from joemcgill/avoid_crops

    Better handling of cropped images
    tevko committed Dec 31, 2014
    Copy the full SHA
    3d674a6 View commit details

Commits on Jan 10, 2015

  1. Create readme.txt

    Needed for wordpress plugin repository
    tevko committed Jan 10, 2015
    Copy the full SHA
    b5c025a View commit details
  2. format edit

    tevko committed Jan 10, 2015
    Copy the full SHA
    0557164 View commit details

Commits on Jan 17, 2015

  1. contribution edit

    tevko committed Jan 17, 2015
    Copy the full SHA
    2b8a103 View commit details

Commits on Jan 18, 2015

  1. Copy the full SHA
    eec1a19 View commit details
  2. filter post thumbnail html

    joemcgill committed Jan 18, 2015
    Copy the full SHA
    6986b36 View commit details

Commits on Jan 19, 2015

  1. Copy the full SHA
    4adac2b View commit details
  2. Copy the full SHA
    c7c0d67 View commit details
  3. Copy the full SHA
    5ee01c1 View commit details
  4. Merge pull request #12 from joemcgill/filter-post-thumbnail

    filter post thumbnail html
    tevko committed Jan 19, 2015
    Copy the full SHA
    5d8d2d1 View commit details

Commits on Jan 21, 2015

  1. add featured image support

    tevko committed Jan 21, 2015
    Copy the full SHA
    a4395ba View commit details
  2. forgot a word

    tevko committed Jan 21, 2015
    Copy the full SHA
    d70283c View commit details
  3. update wordpress plugin readme

    tevko committed Jan 21, 2015
    Copy the full SHA
    470bfd3 View commit details
  4. Copy the full SHA
    bc0e6e9 View commit details
  5. Copy the full SHA
    ccca0e8 View commit details
  6. Update readme.txt

    Stylistic changes: wordpress > WordPress, 4 > four. Added benefit statement/description of responsive images.
    mdmcginn committed Jan 21, 2015
    Copy the full SHA
    4d38ba9 View commit details
  7. Merge pull request #17 from mdmcginn/patch-1

    Update readme.txt
    tevko committed Jan 21, 2015
    Copy the full SHA
    8cc0627 View commit details
  8. reflect plugin name change

    tevko committed Jan 21, 2015
    Copy the full SHA
    6aee6ca View commit details

Commits on Jan 22, 2015

  1. sync up readme

    tevko committed Jan 22, 2015
    Copy the full SHA
    78bdd88 View commit details
  2. Merge pull request #13 from joemcgill/use-default-sizes

    Use native wordpress sizes instead of creating extra crop sizes.
    tevko committed Jan 22, 2015
    Copy the full SHA
    d662bc9 View commit details
  3. Copy the full SHA
    2525a20 View commit details
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[{.jshintrc,*.json,*.yml}]
indent_style = space
indent_size = 2

[{*.txt,wp-config-sample.php}]
end_of_line = crlf
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
25 changes: 25 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"es3": true,
"expr": true,
"immed": true,
"noarg": true,
"onevar": true,
"quotmark": "single",
"trailing": true,
"undef": true,
"unused": true,

"browser": true,

"globals": {
"_": false,
"Backbone": false,
"jQuery": false,
"JSON": false,
"wp": false
}
}
16 changes: 16 additions & 0 deletions .linthub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
go:
lint: false
php:
lint: true
config: ruleset.xml
java:
lint: false
scala:
lint: false
shell:
lint: false
css:
lint: true
js:
lint: jshint # jshint (default) | eslint | false
config: .jshintrc
36 changes: 36 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
language: php

php:
- 5.2
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0

env:
- WP_VERSION=trunk WP_MULTISITE=0
- WP_VERSION=trunk WP_MULTISITE=1
- WP_VERSION=4.3 WP_MULTISITE=0
- WP_VERSION=4.3 WP_MULTISITE=1
- WP_VERSION=4.2 WP_MULTISITE=0
- WP_VERSION=4.2 WP_MULTISITE=1
- WP_VERSION=4.1 WP_MULTISITE=0
- WP_VERSION=4.1 WP_MULTISITE=1
- WP_VERSION=4.0 WP_MULTISITE=0
- WP_VERSION=4.0 WP_MULTISITE=1

allow_failures:
- php: 7.0

fast_finish: true

before_script:
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION

script: phpunit

notifications:
email: false

sudo: false
Binary file added assets/banner-1544x500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/banner-772x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 120 additions & 0 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/usr/bin/env bash

if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
exit 1
fi

DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}

WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}

download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}

if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
WP_TESTS_TAG="tags/$WP_VERSION"
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_TESTS_TAG="trunk"
else
# http serves a single offer, whereas https serves multiple. we only want one
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
if [[ -z "$LATEST_VERSION" ]]; then
echo "Latest WordPress version could not be found"
exit 1
fi
WP_TESTS_TAG="tags/$LATEST_VERSION"
fi

set -ex

install_wp() {

if [ -d $WP_CORE_DIR ]; then
return;
fi

mkdir -p $WP_CORE_DIR

if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p /tmp/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
else
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
fi

download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}

install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i .bak'
else
local ioption='-i'
fi

# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
fi

cd $WP_TESTS_DIR

if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
fi

}

install_db() {
# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""

if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi

# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}

install_wp
install_test_suite
install_db
244 changes: 244 additions & 0 deletions class-respimg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
<?php

/**
* Hacked up version of php-respimg: https://github.com/nwtn/php-respimg
*
* @package wp-respimg
* @version 0.0.1
*/

/**
* An Imagick extension to provide better (higher quality, lower file size) image resizes.
*
* This class extends Imagick (<http://php.net/manual/en/book.imagick.php>) based on
* research into optimal image resizing techniques (<https://github.com/nwtn/image-resize-tests>).
*
* Using these methods with their default settings should provide image resizing that is
* visually indistinguishable from Photoshop’s “Save for Web…”, but at lower file sizes.
*
* @author David Newton <david@davidnewton.ca>
* @copyright 2015 David Newton
* @license https://raw.githubusercontent.com/nwtn/php-respimg/master/LICENSE MIT
* @version 1.0.0
*/

class Respimg extends Imagick {

/**
* Resizes the image using smart defaults for high quality and low file size.
*
* This function is basically equivalent to:
*
* $optim == true: `mogrify -path OUTPUT_PATH -filter Triangle -define filter:support=2.0 -thumbnail OUTPUT_WIDTH -unsharp 0.25x0.08+8.3+0.045 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB INPUT_PATH`
*
* $optim == false: `mogrify -path OUTPUT_PATH -filter Triangle -define filter:support=2.0 -thumbnail OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH`
*
* @access public
*
* @param integer $columns The number of columns in the output image. 0 = maintain aspect ratio based on $rows.
* @param integer $rows The number of rows in the output image. 0 = maintain aspect ratio based on $columns.
* @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.
*/

public function smartResize( $columns, $rows, $optim = false ) {

$this->setOption( 'filter:support', '2.0' );
$this->thumbnailImage( $columns, $rows, false, false, Imagick::FILTER_TRIANGLE );
if ( $optim ) {
$this->unsharpMaskImage( 0.25, 0.08, 8.3, 0.045 );
} else {
$this->unsharpMaskImage( 0.25, 0.25, 8, 0.065 );
}
$this->posterizeImage( 136, false );
$this->setImageCompressionQuality( 82 );
$this->setOption( 'jpeg:fancy-upsampling', 'off' );
$this->setOption( 'png:compression-filter', '5' );
$this->setOption( 'png:compression-level', '9' );
$this->setOption( 'png:compression-strategy', '1' );
$this->setOption( 'png:exclude-chunk', 'all' );
$this->setInterlaceScheme( Imagick::INTERLACE_NO );
$this->setColorspace( Imagick::COLORSPACE_SRGB );
if ( ! $optim ) {
$this->stripImage();
}
}

/**
* Changes the size of an image to the given dimensions and removes any associated profiles.
*
* `thumbnailImage` changes the size of an image to the given dimensions and
* removes any associated profiles. The goal is to produce small low cost
* thumbnail images suited for display on the Web.
*
* With the original Imagick thumbnailImage implementation, there is no way to choose a
* resampling filter. This class recreates Imagick’s C implementation and adds this
* additional feature.
*
* Note: https://github.com/mkoppanen/imagick/issues/90 has been filed for this issue.
*
* @access public
*
* @param integer $columns The number of columns in the output image. 0 = maintain aspect ratio based on $rows.
* @param integer $rows The number of rows in the output image. 0 = maintain aspect ratio based on $columns.
* @param bool $bestfit Treat $columns and $rows as a bounding box in which to fit the image.
* @param bool $fill Fill in the bounding box with the background colour.
* @param integer $filter The resampling filter to use. Refer to the list of filter constants at <http://php.net/manual/en/imagick.constants.php>.
*
* @return bool Indicates whether the operation was performed successfully.
*/

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

/*
* Sample factor; defined in original ImageMagick thumbnailImage function
* the scale to which the image should be resized using the 'sample' function.
*/
$SampleFactor = 5;

// Filter whitelist.
$filters = array(
Imagick::FILTER_POINT,
Imagick::FILTER_BOX,
Imagick::FILTER_TRIANGLE,
Imagick::FILTER_HERMITE,
Imagick::FILTER_HANNING,
Imagick::FILTER_HAMMING,
Imagick::FILTER_BLACKMAN,
Imagick::FILTER_GAUSSIAN,
Imagick::FILTER_QUADRATIC,
Imagick::FILTER_CUBIC,
Imagick::FILTER_CATROM,
Imagick::FILTER_MITCHELL,
Imagick::FILTER_LANCZOS,
Imagick::FILTER_BESSEL,
Imagick::FILTER_SINC
);

// Parse parameters given to function.
$columns = (double) $columns;
$rows = (double) $rows;
$bestfit = (bool) $bestfit;
$fill = (bool) $fill;

// We can’t resize to (0,0).
if ( $rows < 1 && $columns < 1 ) {
return false;
}

// Set a default filter if an acceptable one wasn’t passed.
if ( ! in_array( $filter, $filters ) ) {
$filter = Imagick::FILTER_TRIANGLE;
}

// Figure out the output width and height.
$width = (double) $this->getImageWidth();
$height = (double) $this->getImageHeight();
$new_width = $columns;
$new_height = $rows;

$x_factor = $columns / $width;
$y_factor = $rows / $height;
if ( $rows < 1 ) {
$new_height = round( $x_factor * $height );
} elseif ( $columns < 1 ) {
$new_width = round( $y_factor * $width );
}

/*
* If bestfit is true, the new_width/new_height of the image will be different than
* the columns/rows parameters; those will define a bounding box in which the image will be fit.
*/
if ( $bestfit && $x_factor > $y_factor ) {
$x_factor = $y_factor;
$new_width = round( $y_factor * $width );
} elseif ( $bestfit && $y_factor > $x_factor ) {
$y_factor = $x_factor;
$new_height = round( $x_factor * $height );
}
if ( $new_width < 1 ) {
$new_width = 1;
}
if ( $new_height < 1 ) {
$new_height = 1;
}

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

// if we’d be using sample to scale to smaller than 128x128, just use resize
} elseif ( ( ( $SampleFactor * $new_width ) < 128) || ( ( $SampleFactor * $new_height ) < 128 ) ) {
$this->resizeImage( $new_width, $new_height, $filter, 1 );

// otherwise, use sample first, then resize
} else {
$this->sampleImage( $SampleFactor * $new_width, $SampleFactor * $new_height );
$this->resizeImage( $new_width, $new_height, $filter, 1 );
}

// if the alpha channel is not defined, make it opaque
if ( $this->getImageAlphaChannel() == Imagick::ALPHACHANNEL_UNDEFINED ) {
$this->setImageAlphaChannel( Imagick::ALPHACHANNEL_OPAQUE );
}

// set the image’s bit depth to 8 bits
$this->setImageDepth( 8 );

// turn off interlacing
$this->setInterlaceScheme( Imagick::INTERLACE_NO );

// Strip all profiles except color profiles.
foreach ( $this->getImageProfiles( '*', true ) as $key => $value ) {
if ( $key != 'icc' && $key != 'icm' ) {
$this->removeImageProfile( $key );
}
}

if ( method_exists( $this, 'deleteImageProperty' ) ) {
$this->deleteImageProperty( 'comment' );
$this->deleteImageProperty( 'Thumb::URI' );
$this->deleteImageProperty( 'Thumb::MTime' );
$this->deleteImageProperty( 'Thumb::Size' );
$this->deleteImageProperty( 'Thumb::Mimetype' );
$this->deleteImageProperty( 'software' );
$this->deleteImageProperty( 'Thumb::Image::Width' );
$this->deleteImageProperty( 'Thumb::Image::Height' );
$this->deleteImageProperty( 'Thumb::Document::Pages' );
} else {
$this->setImageProperty( 'comment', '' );
$this->setImageProperty( 'Thumb::URI', '' );
$this->setImageProperty( 'Thumb::MTime', '' );
$this->setImageProperty( 'Thumb::Size', '' );
$this->setImageProperty( 'Thumb::Mimetype', '' );
$this->setImageProperty( 'software', '' );
$this->setImageProperty( 'Thumb::Image::Width', '' );
$this->setImageProperty( 'Thumb::Image::Height', '' );
$this->setImageProperty( 'Thumb::Document::Pages', '' );
}

/*
* In case user wants to fill use extent for it rather than creating a new canvas
* fill out the bounding box.
*/
if ( $bestfit && $fill && ( $new_width != $columns || $new_height != $rows ) ) {
$extent_x = 0;
$extent_y = 0;

if ( $columns > $new_width ) {
$extent_x = ( $columns - $new_width ) / 2;
}

if ( $rows > $new_height ) {
$extent_y = ( $rows - $new_height ) / 2;
}

$this->extentImage( $columns, $rows, 0 - $extent_x, $extent_y );
}

return true;
}
}
230 changes: 230 additions & 0 deletions class-wp-image-editor-respimg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<?php

/**
* WordPress Respimg Imagick Image Editor
*
* @package wp-respimg
* @version 0.0.1
*/

require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' );

/**
* WordPress Image Editor Class for Image Manipulation through Imagick PHP Module with php-respimg.
*
* @package wp-respimg
* @uses WP_Image_Editor_Imagick Extends class
*/
class WP_Image_Editor_Respimg extends WP_Image_Editor_Imagick {

/**
* Loads image from $this->file into new Respimg Object.
*
* @access protected
*
* @return boolean|WP_Error True if loaded; WP_Error on failure.
*/
public function load() {
if ( $this->image instanceof Respimg ) {
return true;
}

if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) {
return new WP_Error( 'error_loading_image', __('File doesn&#8217;t exist?'), $this->file );
}

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

try {
$this->image = new Respimg( $this->file );

if ( ! $this->image->valid() ) {
return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file);
}
// Select the first frame to handle animated images properly.
if ( is_callable( array( $this->image, 'setIteratorIndex' ) ) ) {
$this->image->setIteratorIndex(0);
}

$this->mime_type = $this->get_mime_type( $this->image->getImageFormat() );
} catch ( Exception $e ) {
return new WP_Error( 'invalid_image', $e->getMessage(), $this->file );
}

$updated_size = $this->update_size();
if ( is_wp_error( $updated_size ) ) {
return $updated_size;
}

return $this->set_quality();
}

/**
* Resizes current image.
*
* At minimum, either a height or width must be provided.
* If one of the two is set to null, the resize will
* maintain aspect ratio according to the provided dimension.
*
* @access public
*
* @param int|null $max_w Image width.
* @param int|null $max_h Image height.
* @param boolean $crop
* @return boolean|WP_Error
*/
public function resize( $max_w, $max_h, $crop = false ) {
if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) {
return true;
}

$dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop );
if ( ! $dims ) {
return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions') );
}

list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;

if ( $crop ) {
return $this->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h );
}

try {
if ($this->mime_type === 'image/gif') {
$this->image->scaleImage( $dst_w, $dst_h );
} else {
$this->image->smartResize( $dst_w, $dst_h, false );
}
}
catch ( Exception $e ) {
return new WP_Error( 'image_resize_error', $e->getMessage() );
}

return $this->update_size( $dst_w, $dst_h );
}

/**
* Resize multiple images from a single source.
*
* @access public
*
* @param array $sizes {
* An array of image size arrays. Default sizes are 'small', 'medium', 'large'.
*
* Either a height or width must be provided.
* If one of the two is set to null, the resize will
* maintain aspect ratio according to the provided dimension.
*
* @type array $size {
* @type int ['width'] Optional. Image width.
* @type int ['height'] Optional. Image height.
* @type bool $crop Optional. Whether to crop the image. Default false.
* }
* }
* @return array An array of resized images' metadata by size.
*/
public function multi_resize( $sizes ) {
$metadata = array();
$orig_size = $this->size;
$orig_image = clone $this->image;

foreach ( $sizes as $size => $size_data ) {
if ( ! $this->image ) {
$this->image = clone $orig_image;
}

if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) {
continue;
}

if ( ! isset( $size_data['width'] ) ) {
$size_data['width'] = null;
}
if ( ! isset( $size_data['height'] ) ) {
$size_data['height'] = null;
}

if ( ! isset( $size_data['crop'] ) ) {
$size_data['crop'] = false;
}

$resize_result = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
$duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) );

if ( ! is_wp_error( $resize_result ) && ! $duplicate ) {
$resized = $this->_save( $this->image );

$this->image->clear();
$this->image->destroy();
$this->image = null;

if ( ! is_wp_error( $resized ) && $resized ) {
unset( $resized['path'] );
$metadata[$size] = $resized;
}
}

$this->size = $orig_size;
}

$this->image = $orig_image;

return $metadata;
}

/**
* Crops Image.
*
* @access public
*
* @param int $src_x The start x position to crop from.
* @param int $src_y The start y position to crop from.
* @param int $src_w The width to crop.
* @param int $src_h The height to crop.
* @param int $dst_w Optional. The destination width.
* @param int $dst_h Optional. The destination height.
* @param boolean $src_abs Optional. If the source crop points are absolute.
* @return boolean|WP_Error
*/
public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) {
if ( $src_abs ) {
$src_w -= $src_x;
$src_h -= $src_y;
}

try {
$this->image->cropImage( $src_w, $src_h, $src_x, $src_y );
$this->image->setImagePage( $src_w, $src_h, 0, 0);

if ( $dst_w || $dst_h ) {
/*
* If destination width/height isn't specified, use same as
* width/height from source.
*/
if ( ! $dst_w ) {
$dst_w = $src_w;
}

if ( ! $dst_h ) {
$dst_h = $src_h;
}

if ($this->mime_type === 'image/gif') {
$this->image->scaleImage( $dst_w, $dst_h );
} else {
$this->image->smartResize( $dst_w, $dst_h, false );
}
return $this->update_size();
}
} catch ( Exception $e ) {
return new WP_Error( 'image_crop_error', $e->getMessage() );
}
return $this->update_size();
}
}
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name" : "ResponsiveImagesCG/wp-tevko-responsive-images",
"description": "Fully responsive image plugin for WordPress.",
"homepage" : "https://github.com/ResponsiveImagesCG/wp-tevko-responsive-images",
"type" : "wordpress-plugin",
"license" : "GPL-2.0+",
"require" : {
"composer/installers": "~1.0"
}
}
555 changes: 0 additions & 555 deletions js/picturefill-dev.js

This file was deleted.

4 changes: 0 additions & 4 deletions js/picturefill.js

This file was deleted.

5 changes: 5 additions & 0 deletions js/picturefill.min.js
14 changes: 14 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
617 changes: 589 additions & 28 deletions readme.md

Large diffs are not rendered by default.

159 changes: 159 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
=== RICG Responsive Images ===
Contributors: tevko, wilto, joemcgill, jaspermdegroot, chriscoyier, Michael McGinnis, ryelle, drrobotnik, nacin, georgestephanis, helen, wordpressdotorg, Bocoup
Donate link: https://app.etapestry.com/hosted/BoweryResidentsCommittee/OnlineDonation.html
Tags: Responsive, Images, Responsive Images, SRCSET, Picturefill
Requires at least: 4.0
Tested up to: 4.4
Stable tag: 3.1.1
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.txt

Bringing automatic default responsive images to WordPress.

== Description ==

Bringing automatic default responsive images to WordPress.

This plugin works by including all available image sizes for each image upload. Whenever WordPress outputs the image through the media uploader, or whenever a featured image is generated, those sizes will be included in the image tag via the srcset attribute.

**Important notes**

* As of WordPress 4.4, images are responsive by default. If you are on WordPress 4.4 or plan to update, you will not need to install this plugin.

If you have had this plugin installed since before version 2.5 but are running version 4.4 of WordPress, it is important that you leave the plugin installed. This is because all versions of the plugin before version 2.5 relied on a `data-sizes` attribute being present on an image in order to provide the responsive markup needed. If the plugin in this case is removed, then images in posts will be left with invalid markup. We are working to address this issue, and you can keep track of our progress here at https://github.com/ResponsiveImagesCG/wp-tevko-responsive-images/issues/178.

You can still use the plugin for advanced image compression support or as a simple way to include the picturefill script. The plugin will fall back to WordPress default functions if responsive image support is detected in your installation.


* Version 3.1.0 includes important changes that make this plugin compatible with WordPress version 4.4. Upgrading is highly recommended.

* As of version 2.5.0, the plugin adds `srcset` and `sizes` attributes to images on the front end instead of adding them to the image markup saved in posts.

**Full documentation and contributor guidelines can be found on [Github](https://github.com/ResponsiveImagesCG/wp-tevko-responsive-images)**

== Installation ==

1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. If you'd like to enable the advanced image compression feature, Please see the instructions at https://github.com/ResponsiveImagesCG/wp-tevko-responsive-images/tree/dev#advanced-image-compression

== Changelog ==

= 3.1.1 =
* Fixes a bug where the srcset of images in imported content was missing or broken.
* Improved calculation of ratio difference for images to be included in the srcset.
* Fixes a bug where `img` tags without ending slash don't get responsive images.
* Deprecates the helper function `tevkori_get_media_embedded_in_content()` which is no longer used.
* Makes sure that the setup of default themes doesn't break the tests.
* Adds more examples to the Hook Reference in readme.md.
* Corrections and improvements to inline documentation.

= 3.1.0 =
* Adds special handling of GIFs in srcset attributes to preserve animation.
* Makes internal srcset/sizes functions more consistent.
* Fixes a bug where functions hooked into `tevkori_image_sizes_args` were not firing.
* Fixes a bug where custom sizes attributes added via the post editor were being overwritten.
* Deprecates hook `wp_get_attachment_image_sizes`.
* Fixes a bug where `the_post_thumbnail()` would fail to add srcset/sizes attributes.
* Several improvements to internal inline documentation.
* Major improvements to function/hook documentation in readme.md after 3.0.0 changes.

= 3.0.0 =
* Deprecates all core functions that will be merged into WordPress core in 4.4.
* Adds compatibility shims for sites using the plugin's internal functions and hooks.
* Adds a new display filter callback which can be use as general utility function for adding srcset and sizes attributes.
* Fixes a bug when `wp_get_attachment_metadata()` failed to return an array.
* Update our tests to be compatible with WordPress 4.4
* Upgrade to Picturefill 3.0.1
* Clean up inline docs.

= 2.5.2 =
* Numerous performance and usability improvements
* Pass height and width to `tevkori_get_sizes()`
* Improved regex in display filter
* Avoid calling `wp_get_attachment_image_src()` in srcset functions
* Improved coding standards
* Removed second regular expression in content filter
* Improved cache warning function
* Change default `$size` value for all functions to 'medium'

= 2.5.1 =
* Query all images in single request before replacing
* Minor fix to prevent a potential undefined variable notice
* Remove third fallback query from the display filter

= 2.5.0 =
* Responsify all post images by adding `srcset` and `sizes` through a display filter.
* Improve method used to build paths in `tevkori_get_srcset_array()`
* Added Linthub config files
* Returns single source arrays in `tevkori_get_srcset_array()`
* Add tests for PHP7 to our Travis matrix
* Add test coverage for `tevkori_filter_attachment_image_attributes()`

= 2.4.0 =
* Added filter for `tevkori_get_sizes`, with tests
* Added Composer support
* Compare aspect ratio in relative values, not absolute values
* Cleanup of code style and comments added
* Added PHP 5.2 to our Travis test matrix
* Fixed unit test loading
* Preventing duplicates in srcset array
* Updated docs for advanced image compression
* Formatting cleanup in readme.md
* Bump plugin 'Tested up to:' value to 4.3
* Remove extra line from readme.txt
* Added changelog items from 2.3.1 to the readme.txt file
* Added 'sudo: false' to travis.ci to use new TravisCI infrastructure
* Removing the srcset and sizes attributes if there is only one source present for the image
* Use edited image hash to filter out originals from edited images
* Make output of `tevkori_get_srcset_array` filterable

= 2.3.1 =
* First char no longer stripped from file name if there's no slash
* Adding test for when uploads directory not organized by date
* Don't calculate a srcset when the image data returns no width
* Add test for image_downsize returning 0 as a width

= 2.3.0 =
* Improved performance of get_srcset_array
* Added advanced image compression option (available by adding hook to functions.php)
* Duplicate entires now filtered out from srcset array
* Upgrade Picturefill to 2.3.1
* Refactoring plugin JavaScript, including a switch to ajax for updating the srcset value when the image is changed in the editor
* Now using `wp_get_attachment_image_attributes` filter for post thumbnails
* Readme and other general code typo fixes
* Gallery images will now contain a srcset attribute

= 2.2.1 =
* Patch fixing missing JavaScript error

= 2.2.0 =
* The mandatory sizes attribute is now included on all images
* Updated to Picturefill v2.3.0
* Extensive documentation included in readme
* Integrated testing with Travis CLI
* Check if wp.media exists before running JavaScript
* Account for rounding variance when matching ascpect ratios

= 2.1.1 =
* Adding in wp-tevko-responsive-images.js after file not found to be in WordPress repository
* Adjusts the aspect ratio check in `tevkori_get_srcset_array()` to account for rounding variance

= 2.1.0 =
* **This version introduces a breaking change**: There are now two functions. One returns an array of srcset values, and the other returns a string with the `srcset=".."` html needed to generate the responsive image. To retrieve the srcset array, us `tevkori_get_srcset_array( $id, $size )`
* When the image size is changed in the post editor, the srcset values will adjust to match the change.

= 2.0.2 =
* A bugfix correcting a divide by zero error. Some users may have seen this after upgrading to 2.0.1

= 2.0.1 =
* Only outputs the default WordPress sizes, giving theme developers the option to extend as needed
* Added support for featured images

= 2.0.0 =
* Uses [Picturefill 2.2.0 (Beta)](http://scottjehl.github.io/picturefill/)
* Scripts are output to footer
* Image sizes adjusted
* Most importantly, the srcset syntax is being used
* Works for cropped images!
* Backwards compatible (images added before plugin install will still be responsive)!
88 changes: 88 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0"?>
<ruleset name="WordPress Core">
<description>Non-controversial generally-agreed upon WordPress Coding Standards</description>

<!-- http://make.wordpress.org/core/handbook/coding-standards/php/#brace-style -->
<rule ref="Generic.ControlStructures.InlineControlStructure" />
<rule ref="Squiz.ControlStructures.ControlSignature" />
<rule ref="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace">
<severity>0</severity>
</rule>

<!-- http://make.wordpress.org/core/handbook/coding-standards/php/#remove-trailing-spaces -->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>

<!-- http://make.wordpress.org/core/handbook/coding-standards/php/#no-shorthand-php-tags -->
<rule ref="Generic.PHP.DisallowShortOpenTag"/>

<!-- important to prevent issues with content being sent before headers -->
<rule ref="Generic.Files.ByteOrderMark"/>

<!-- http://make.wordpress.org/core/handbook/coding-standards/php/#naming-conventions -->
<rule ref="Generic.PHP.LowerCaseConstant"/>

<!-- http://make.wordpress.org/core/handbook/coding-standards/php/#indentation -->
<arg name="tab-width" value="4"/>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="4"/>
<property name="tabIndent" value="true"/>
</properties>
</rule>

<!-- http://make.wordpress.org/core/handbook/coding-standards/php/#error-control-operator -->
<rule ref="Generic.PHP.NoSilencedErrors" />

<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
<severity>0</severity>
</rule>

<rule ref="Generic.PHP.LowerCaseKeyword"/>

<rule ref="Generic.Files.LineEndings">
<properties>
<property name="eolChar" value="\n"/>
</properties>
</rule>


<rule ref="Generic.Files.EndFileNewline"/>

<!-- https://make.wordpress.org/core/handbook/coding-standards/php/#naming-conventions -->
<rule ref="Generic.Files.LowercasedFilename"/>

<!-- https://make.wordpress.org/core/handbook/coding-standards/php/#space-usage -->
<rule ref="Generic.Formatting.SpaceAfterCast"/>

<!-- https://make.wordpress.org/core/handbook/coding-standards/php/#brace-style -->
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie"/>

<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="requiredSpacesAfterOpen" value="1" />
<property name="requiredSpacesBeforeClose" value="1" />
</properties>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine">
<severity>0</severity>
</rule>

<rule ref="WordPress.Arrays.ArrayDeclaration">
<exclude name="WordPress.Arrays.ArrayDeclaration.SingleLineNotAllowed" />
</rule>
<rule ref="WordPress.Arrays.ArrayKeySpacingRestrictions"/>
<rule ref="WordPress.Classes.ValidClassName"/>
<rule ref="WordPress.Files.FileName"/>
<rule ref="WordPress.Functions.FunctionDeclarationArgumentSpacing"/>
<rule ref="WordPress.NamingConventions.ValidFunctionName"/>
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing"/>
<rule ref="WordPress.WhiteSpace.OperatorSpacing"/>
<rule ref="WordPress.WhiteSpace.CastStructureSpacing"/>
<rule ref="WordPress.PHP.YodaConditions"/>

</ruleset>
34 changes: 34 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
$_tests_dir = false;

// ../tests ../{plugin} ../plugins
$dir = dirname( __FILE__ );

if ( 'plugins' === basename( dirname( dirname( $dir ) ) ) ) {
$plugins = dirname( dirname( $dir ) );
// wordpress core svn = ../wp-content ../src
$step = dirname( dirname( $plugins ) );
$tests = '/tests/phpunit';
if ( 'src' === basename( $step ) ) {
$_tests_dir = dirname( $step ) . $tests;
// wordpress git = ../wp-content ../{root}
} elseif ( is_dir( $step . '/tests' ) ) {
$_tests_dir = $step . $tests;
}
}

if ( ! $_tests_dir ) {
$_tests_dir = getenv( 'WP_TESTS_DIR' );
if ( ! $_tests_dir ) {
$_tests_dir = '/tmp/wordpress-tests-lib';
}
}

require_once( $_tests_dir . '/includes/functions.php' );

function _manually_load_plugin() {
require dirname( __FILE__ ) . '/../wp-tevko-responsive-images.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

require( $_tests_dir . '/includes/bootstrap.php' );
Binary file added tests/data/test-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
712 changes: 712 additions & 0 deletions tests/test-suite.php

Large diffs are not rendered by default.

490 changes: 490 additions & 0 deletions wp-tevko-core-functions.php

Large diffs are not rendered by default.

457 changes: 457 additions & 0 deletions wp-tevko-deprecated-functions.php

Large diffs are not rendered by default.

135 changes: 73 additions & 62 deletions wp-tevko-responsive-images.php
Original file line number Diff line number Diff line change
@@ -1,78 +1,89 @@
<?php
/**
* @link https://github.com/ResponsiveImagesCG/wp-tevko-responsive-images
* @since 2.0.0
* @package http://www.smashingmagazine.com/2015/02/24/ricg-responsive-images-for-wordpress/
*
* @wordpress-plugin
* Plugin Name: RICG Responsive Images
* Plugin URI: https://github.com/ResponsiveImagesCG/wp-tevko-responsive-images
* Description: Bringing automatic default responsive images to WordPress
* Version: 3.1.1
* Author: The RICG
* Author URI: http://responsiveimages.org/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/

// Don't load the plugin directly.
defined( 'ABSPATH' ) or die( "No script kiddies please!" );

/*
Plugin Name: WP Tevko Responsive Images
Plugin URI: http://timevko.com
Description: Fully responsive image solution using picturefill and the ID of your image.
Version: 1.0.1
Author: Tim Evko
Author URI: http://timevko.com
License: MIT
*/
* Include the advanced image compression files.
* See readme.md for more information.
*/
if ( class_exists( 'Imagick' ) ) {
require_once( plugin_dir_path( __FILE__ ) . 'class-respimg.php' );
require_once( plugin_dir_path( __FILE__ ) . 'class-wp-image-editor-respimg.php' );

/**
* Filter to add php-respimg as an image editor.
*
* @since 2.3.0
*
* @return array Editors.
**/
function tevkori_wp_image_editors( $editors ) {
if ( current_theme_supports( 'advanced-image-compression' ) ) {
array_unshift( $editors, 'WP_Image_Editor_Respimg' );
}

// First we queue the polyfill
function tevkori_get_picturefill() {
wp_enqueue_script( 'picturefill', plugins_url( '/js/picturefill.js', __FILE__ ) );
return $editors;
}
add_filter( 'wp_image_editors', 'tevkori_wp_image_editors' );
}
add_action( 'wp_enqueue_scripts', 'tevkori_get_picturefill' );

// Load the deprecated core functions.
require_once( plugin_dir_path( __FILE__ ) . 'wp-tevko-deprecated-functions.php' );

// Add support for our desired image sizes - if you add to these, you may have to adjust your shortcode function
// TODO: Add UI for adjusting?
function tevkori_add_image_sizes() {
add_image_size( 'large-img', 1000, 702 );
add_image_size( 'medium-img', 700, 372 );
add_image_size( 'small-img', 300, 200 );
}
add_action( 'plugins_loaded', 'tevkori_add_image_sizes' );

// alt tags will now be automatically included
function tevkori_get_img_alt( $image ) {
$img_alt = trim( strip_tags( get_post_meta( $image, '_wp_attachment_image_alt', true ) ) );
return $img_alt;
/*
* Load copies of our core functions if the plugin is installed on a version of WordPress
* previous to 4.4, when the functions were added to core.
*/
if ( ! function_exists( 'wp_get_attachment_image_srcset' ) ) {
require_once( plugin_dir_path( __FILE__ ) . 'wp-tevko-core-functions.php' );
}

function tevkori_get_picture_srcs( $image, $mappings ) {
$arr = array();
foreach ( $mappings as $size => $type ) {
$image_src = wp_get_attachment_image_src( $image, $type );
$arr[] = '<source srcset="'. $image_src[0] . '" media="(min-width: '. $size .'px)">';
}
return implode( array_reverse ( $arr ) );
// Enqueue bundled version of the Picturefill library.
function tevkori_get_picturefill() {
wp_enqueue_script( 'picturefill', plugins_url( 'js/picturefill.min.js', __FILE__ ), array(), '3.0.1', true );
}
add_action( 'wp_enqueue_scripts', 'tevkori_get_picturefill' );

function tevkori_responsive_shortcode( $atts ) {
extract( shortcode_atts( array(
'imageid' => 1,
// You can add more sizes for your shortcodes here
'size1' => 0,
'size2' => 600,
'size3' => 1000,
), $atts ) );
/**
* Filter to add 'srcset' and 'sizes' attributes to post thumbnails and gallery images.
* The filter is added to the hook in wp-tevko-core-functions.php because
* it is only needed on a version of WordPress previous to 4.4.
*
* @since 2.3.0
* @see 'wp_get_attachment_image_attributes'
*
* @return array Attributes for image.
*/
function tevkori_filter_attachment_image_attributes( $attr, $attachment, $size ) {
// Set 'srcset' and 'sizes' if not already present and both were returned.
if ( empty( $attr['srcset'] ) ) {
$srcset = wp_get_attachment_image_srcset( $attachment->ID, $size );
$sizes = wp_get_attachment_image_sizes( $attachment->ID, $size );

$mappings = array(
$size1 => 'small-img',
$size2 => 'medium-img',
$size3 => 'large-img'
);
if ( $srcset && $sizes ) {
$attr['srcset'] = $srcset;

return
'<picture>
<!--[if IE 9]><video style="display: none;"><![endif]-->'
. tevkori_get_picture_srcs( $imageid, $mappings ) .
'<!--[if IE 9]></video><![endif]-->
<img srcset="' . wp_get_attachment_image_src( $imageid[0] ) . '" alt="' . tevkori_get_img_alt( $imageid ) . '">
<noscript>' . wp_get_attachment_image( $imageid, $mappings[0] ) . ' </noscript>
</picture>';
}
// TODO: It this the best name? responsive_img? picture?
add_shortcode( 'responsive', 'tevkori_responsive_shortcode' );
if ( empty( $attr['sizes'] ) ) {
$attr['sizes'] = $sizes;
}
}
}

// Alter Media Uploader output to output shortcode instead
// TODO: Make optional?
// TODO: Make this know what sizes are chosen, rather than hardcoded
function tevkori_responsive_insert_image( $html, $id, $caption, $title, $align, $url ) {
return "[responsive imageid='$id' size1='0' size2='600' size3='1000']";
return $attr;
}
add_filter( 'image_send_to_editor', 'tevkori_responsive_insert_image', 10, 9 );