Welcome Guest, Not a member yet? Register   Sign In
Image Manipulation
#1

I can't understand what the syntax for image manipulation is. I have this in my controller, which moves the renamed image to the folder and saves its name in the database.

However, I would like to manage the resize, but I cannot understand where to act. This is my controller:


PHP Code:
$data['validation']->setRules([
            'first_name' => ['label' => 'First Name''rules' => 'required|min_length[3]|max_length[150]'],
            'last_name' => ['label' => 'Last Name''rules' => 'required|min_length[5]|max_length[150]'],
            'bio' => ['label' => 'Bio''rules' => 'required|min_length[15]'],
            'category' => ['label' => 'Category''rules' => 'required'],
            'photo' => ['label' => 'Photo''rules' => 'uploaded[photo]|max_size[photo,1024]'],
        ]);
        
        
if($this->request->getPost() && $data['validation']->withRequest($this->request)->run()) {

            // store photo in folder writable/uploads/photos
            if($imagefile $this->request->getFiles('photo')){
                if($img $imagefile['photo']){
                    if($img->isValid() && ! $img->hasMoved()){
                        $newName $img->getRandomName();
                        $img->move(WRITEPATH.'uploads/photos'$newName);
                    }
                }
            }
            
            $fields 
= [
                'first_name' => $this->request->getVar('first_name'),
                'last_name'  => $this->request->getVar('last_name'),
                'bio'  => $this->request->getVar('bio'),
                'category'  => $this->request->getVar('category'),
                'photo' => $newName,

...... 

Where should I enter this?

PHP Code:
$image = \Config\Services::image()
        ->withFile('/path/to/image/mypic.jpg')
        ->fit(100100'center')
        ->save('/path/to/image/mypic_thumb.jpg'); 

I don't need you to upload two photos (original and miniature), but only the reduced image.
Reply
#2

(This post was last modified: 04-14-2020, 03:58 PM by Leo.)

I did this 2 days ago! Or yesterday maybe...

basically, you don't need this (unless you want to run more security checks on the file before moving itto desired folder? or keep the original?): $img->move(WRITEPATH.'uploads/photos', $newName);
just fiddle with the temporary upload path

if($img->isValid() && ! $img->hasMoved()){
$newName = $img->getRandomName();
//$img->move(WRITEPATH.'uploads/photos', $newName); <--- not needed
$source = $img->getTempName();
$image = \Config\Services::image()
->withFile($source)
->fit(100, 100, 'center')
->save($targetDirectory.'/'.$newName);
}
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply
#3

Great, thank you very much.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB