Wallogit.com
2017 © Pedro Peláez
Image sizes helper for forWordPress
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"]
));
};
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;
}
}
$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)