ShowImage.php
654 Bytes
<?php
namespace common\behaviors;
use yii;
use yii\base\Behavior;
class ShowImage extends Behavior
{
function minImg($dir, $width, $height=null){
if(empty($dir)){
return $dir;
}
if($width=='original'){
$preg = '/\/(.[^\/]*)$/';
preg_match('/\.(.[^.]*)$/', $dir, $type);
$row = preg_replace( $preg, '/original.'.$type[1], $dir);
} else {
$preg = '/\/(.[^\/]*)$/';
preg_match('/\.(.[^.]*)$/', $dir, $type);
$row = preg_replace( $preg, '/'.$width.'X'.$height.'.'.$type[1], $dir);
}
return $row;
}
}