The answer is obviously, Yes, You Can. :)
If you disable this third party extension either via editing code or via admin, then magento will start to use its default helper/Model class. Yes Magento is smart enough to to do that.
In order to disable this extension via admin, you need to go
System > Configuration > Advanced
In order to disable via xml file, you need to find activation file of the extension. Most probably it's name would be Kadro_PIO.xml
. So go to app\etc\modules\Kadro_PIO.xml
and then change
<active>false</active>
Edit
From your comment, it seems that, the extension do other jobs for you. So my solution will not help you, since it disable that extension fully.
If you just need to avoid the rewrite part, then the fastest and easiest way will be comment out that rewrite part in the extension's config.xml
file.
But this is not the proper way to do this. If you need to do this in clear way, then I will suggest you to create a small custom module that will rewrite the extension's rewrite model file.
For this your module config.xml
should holds this part
File : app\code\local\Namespace\Modulename\etc\config.xml
<global>
<models>
<pio>
<rewrite>
<product_image>Namespace_Modulename_Model_Product_Image</product_image>
</rewrite>
</pio>
</models>
</globlal>
File : app\code\local\Namespace\Modulename\Model\Product\Image.php
<?php
class Namespace_Modulename_Model_Product_Image extends Kadro_PIO_Model_Product_Image
{
//here you can overwrite any method that extension uses
}
Managed to put together a working solution for now by overriding the magento 2 product image class
Create a new module with the standard module.xml, registration.php, composer.json as needed.
Crete etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Model\Product\Image" type="Vendor\Imagecrop\Model\Product\Image" />
</config>
Create Model/Product/Image.php
<?php
namespace Vendor\Imagecrop\Model\Product;
class Image extends \Magento\Catalog\Model\Product\Image
{
/**
* @see \Magento\Framework\Image\Adapter\AbstractAdapter
* @return $this
*/
public function resize()
{
if (is_null($this->getWidth()) && is_null($this->getHeight())) {
return $this;
}
// if given both dimensions crop to take up max of both dimensions
if(!is_null($this->getWidth()) && !is_null($this->getHeight())){
$new_width = $this->_width;
$new_height = $this->_height;
$this->getImageProcessor();
$orig_width = $this->_processor->getOriginalWidth();
$orig_height = $this->_processor->getOriginalHeight();
$new_ratio = $new_width / $new_height;
$orig_ratio = $orig_width / $orig_height;
// if original has wider dimensions than new dimensions
if($orig_ratio > $new_ratio){
$temp_width = round($orig_ratio * $new_height);
$tmp_constrain = $this->_constrainOnly;
$this->setConstrainOnly(false);
$this->getImageProcessor()->resize($temp_width, $new_height);
$this->setConstrainOnly($tmp_constrain);
$crop_amount = floor(($temp_width - $new_width) / 2);
$crop_remainder = ($temp_width - $new_width) % 2;
$this->_processor->crop(0, $crop_amount + $crop_remainder, $crop_amount, 0);
// if original has taller dimensions than new dimensions
} else {
$temp_height = round((1 / $orig_ratio) * $new_width);
$tmp_constrain = $this->_constrainOnly;
$this->setConstrainOnly(false);
$this->getImageProcessor()->resize($new_width, $temp_height);
$this->setConstrainOnly($tmp_constrain);
$crop_amount = floor(($temp_height - $new_height) / 2);
$crop_remainder = ($temp_height - $new_height) % 2;
$this->_processor->crop($crop_amount + $crop_remainder, 0, 0, $crop_amount);
}
} else {
$this->getImageProcessor()->resize($this->_width, $this->_height);
}
return $this;
}
}
This should change default behavious so when you have frame, aspect ratio set to false and constrain all set to true instead of resizing to the given size by stretching it will resize the shortest dimension and crop off the ends.
Still testing this code so use at own risk.
Best Answer
What you can do is, take what the method is returning, strip the baseurl from it, so you have the path in /media/ and then use getimagesize