0
How to adapt the plugin Croppic for cutting images?
I have two files that I turned into Ibraries, but I can’t pass the parameters to that library
.
The plugin is this: https://github.com/sconsult/croppic
Code used this below.
Controller:
public function cropimg() {
if($_POST) {
$imgUrl = $_POST['imgUrl'];
$imgInitW = $_POST['imgInitW'];
$imgInitH = $_POST['imgInitH'];
$imgW = $_POST['imgW'];
$imgH = $_POST['imgH'];
$imgY1 = $_POST['imgY1'];
$imgX1 = $_POST['imgX1'];
$cropW = $_POST['cropW'];
$cropH = $_POST['cropH'];
}
$this->cropfile->imgCrop($imgUrl, $imgInitW, $imgInitH, $imgW, $imgH, $imgY1, $imgX1, $cropW, $cropH);
}
Library:
class CropFile {
public function imgCrop($imgUrl, $imgInitW, $imgInitH, $imgW, $imgH, $imgY1, $imgX1, $cropW, $cropH)
{
$CI =& get_instance();
$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url');
$jpeg_quality = 100;
$output_filename = base_url() . "public/croppedImg_".rand();
$what = getimagesize($imgUrl);
switch(strtolower($what['mime']))
{
case 'image/png':
$img_r = imagecreatefrompng($imgUrl);
$source_image = imagecreatefrompng($imgUrl);
$type = '.png';
break;
case 'image/jpeg':
$img_r = imagecreatefromjpeg($imgUrl);
$source_image = imagecreatefromjpeg($imgUrl);
$type = '.jpeg';
break;
case 'image/gif':
$img_r = imagecreatefromgif($imgUrl);
$source_image = imagecreatefromgif($imgUrl);
$type = '.gif';
break;
default: die('image type not supported');
}
$resizedImage = imagecreatetruecolor($imgW, $imgH);
imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW,
$imgH, $imgInitW, $imgInitH);
$dest_image = imagecreatetruecolor($cropW, $cropH);
imagecopyresampled($dest_image, $resizedImage, 0, 0, $imgX1, $imgY1, $cropW,
$cropH, $cropW, $cropH);
imagejpeg($dest_image, $output_filename.$type, $jpeg_quality);
$response = array(
"status" => 'success',
"url" => $output_filename.$type
);
print json_encode($response);
}
You are loading this library into the controller?
– Alex Juchem
I am, @Alexjuchem, but the parameters are not going
– Uellington Palma
Where is your library loading into your controller? You should have some part either in autoload or __Construct or even in the method itself
$this->load->library('cropfile');
– Marcelo Diniz
And you have already looked at the documentation https://ellislab.com/codeigniter/user-guide/general/creating_libraries.html can only be a matter of class and method names, for example from Cropfile to Cropfile
– Marcelo Diniz