2017 © Pedro Peláez
 

library component-image-size

Image sizes helper for forWordPress

image

flexpress/component-image-size

Image sizes helper for forWordPress

  • Wednesday, August 20, 2014
  • by timperry
  • Repository
  • 1 Watchers
  • 0 Stars
  • 67 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

FlexPress image size component

Install with Pimple

The image size component uses two classes: - AbstractImageSize, which you extend to create a image size. - ImageSizeHelper, which hooks into everything for you and registers the image sizes. - Lets create a pimple config for both of these, (*1)

$pimple["featureImageSize"] = function () {
  return new FeatureImageSize();
};

$pimple['imageSizeHelper'] = function ($c) {
    return new ImageSizeHelper($c['objectStorage'], array(
        $c["featureImageSize"]
    ));
};
  • Note the dependency $c['objectStorage'] is a SPLObjectStorage

Creating a concreate ImageSize class

Create a concreate class that implements the AbstractImageSize class and implements the getName(), getHeight() and getWidth() methods., (*2)

class Feature extends AbstractImageSize {

    public function getName()
    {
        return "Feature";
    }

    public function getHeight()
    {
        return 200;
    }

    public function getWidth()
    {
        return 600;
    }
}

This above example is the bare minimum you must implement, the example that follows is the other extreme implementing all available methods., (*3)

class Feature extends AbstractImageSize {

    public function getName()
    {
        return "Feature";
    }

    public function getHeight()
    {
        return 200;
    }

    public function getWidth()
    {
        return 600;
    }

    public function getCrop()
    {
        return false;
    }

    public function shouldShowInCMS()
    {
        return false;
    }

}

Public Methods

  • getName() - returns the name of the image size.
  • getHeight() - returns the height of the image size.
  • getWidth() - returns the width of the image size.
  • getCrop() - Boolean value to state if the image should be cropped.
  • shouldShowInCMS() - Whether the image size should be selectable in the CMS, e.g. when inserting media into a post

ImageSizeHelper usage

  • Once you have setup the pimple config you are use the ImageSizeHelper like this
$helper = $pimple['imageSizeHelper'];
$helper->registerImageSizes();

That's it, the helper will then add all the needed hooks and register all the image sizes you have provided it., (*4)

Public methods

  • imageSizeNamesChoose() - Used by a hook to add the images to the available image sizes in WordPress UI (uses the shouldShowInCMS method of the imagesize class.
  • registerImageSizes() - Used by a hook to add the image sizes provided.

The Versions

20/08 2014

dev-master

9999999-dev

Image sizes helper for forWordPress

  Sources   Download

13/08 2014

v1.0.0

1.0.0.0

Image sizes helper for forWordPress

  Sources   Download