Crop image using image tool component in cakephp

1

I'm using a plugin

Image tool component

for which I have created a function, which I use after each upload of the images as follows

//Función para recotar imagen 
private function _risizeimage($image){
    $img = ImageTool::resize([
                    'input' => $image,
                    'output' => $image,
                    'width' => 100,
                    'height' => 100,
                    'keepRatio' => true,
                ]);
                return $img;
}

here the function to load the images

public function publicadd() {

    $publicadd = $this->Advertisements->newEntity($this->request->data);
    if($this->request->is('post')){
        $publicadd->id_user = $this->Auth->user('id_user');
        $publicadd = $this->Advertisements->patchEntity($publicadd,$this->request->data);
        if ($this->Advertisements->save($publicadd)) {
            $id = $publicadd->id_advertisement;
            $publicaddimg = $this->AdvertisementsImagenes->query();
            //Variable que uso para recuperar las imagenes cargadas
            $images = $this->request->data['name_imagen'];
            foreach ($images as $image){
                $imgname = $image['name'];
                // Variable para recortar imagen
                $img = $this->_risizeimage($imgname);
                $data = [
                    'id_advertisement' => $id,
                    'name_imagen' => $image['tmp_name']
                ];
                $publicaddimg->insert(['id_advertisement','name_imagen'])
                        ->values($data);
                new Folder(WWW_ROOT . 'anuncios',true,0755);
                // Funcion para cargar imagen al servidor
                $mv = new File($img['tmp_name']);
                $mv->copy(WWW_ROOT . 'anuncios/'.$img['tmp_name']);
            }
            $publicaddimg->execute();
            $this->Flash->success('Anuncio Publicado');
            $this->redirect(['controller' => 'Home','action' => 'index']);
        }else{
            $this->Flash->error('Error al momento de guardar el registro');
        }
    }
}

The problem is that it does not make the upload and the clipping as such I do not know if I'm doing something wrong, please help I've been several days with this Thanks

    
asked by Jonathan Cunza 11.01.2017 в 15:43
source

2 answers

0

In the end I am like this, the method to trim

private function _risizeimage($image,$output){ 
$img = ImageTool::resize(array( 
'input' => $image, 
'output' => $output, 
'width' => 100, 
'height' => 100, 
'keepRatio' => true, 
));     
return $img; 
}

the execution of the foreach

foreach ($images as $image){ 
$imgname = $image['tmp_name']; 
$img = $this->_risizeimage($imgname, WWW_ROOT.'anuncions/'.$image['name']); 

}
    
answered by 11.01.2017 / 21:40
source
0

My code is right now

private function _risizeimage($image){
    $img = ImageTool::resize(array(
                    'input' => $image,
                    'output' => 'img.jgp',
                    'width' => 100,
                    'height' => 100,
                    'keepRatio' => true,
                ));
                return ImageTool::saveImage($img,array(
                    'output' => 'img.jgp'
                ));
}

//envio archivo para ser procesado
$imgname = $image['tmp_name'];
                $img = $this->_risizeimage($imgname);
                var_dump($img);
                die();
    
answered by 11.01.2017 в 22:09