08-19-2017, 04:54 AM
Good day, am trying to resize on upload, seems not to be working out. it shows this error "imagecopyresampled(): supplied resource is not a valid Image resource" after resizing to just one folder.
PHP Code:
if ($imagefile = $this->request->getFile('avatar'))
{
if ($imagefile->isValid() && ! $imagefile->hasMoved())
{
$path = FCPATH.'profile/';
$filename = $imagefile->getRandomName();
$file_full_path = $path . $filename;
if($imagefile->move($path, $filename))
{
$sizes = array('600','920','200');
foreach ($sizes as $size)
{
$resizepath = $imagefile->setPath($path.$size.'/');
\Config\Services::image('gd')
->withFile($file_full_path)
->resize($size, 230,true, 'height')
->save($resizepath.$filename);
}
$result['status'] = 200;
$result['image'] = $path.'200/'.$filename;
}
}
}