Resize image works with v030 but not with v0.34

See all posts Reply

Resize image works with v030 but not with v0.34 new!
by Patrice, 6 years, 3 months ago
Hello,

I use Codeigniter from several years and add class.upload as a librairie.

Works fine.

I replace by v0.34 and I use the same code, but there is no resize.

/**
 * Gestion des photos de l'utilisateur
 */
public function photo()
{
  $this->load->model('users_model');
  $data['infos_header'] = array('titre' =>'Gestion de votre photo');
  $data['vue_contenu'] = 'profil/photo';
  $data['menu_accueil'] = true;
  $data['menu_agents'] = true;
  $do_upload=false;
  if(isset($_FILES['photo']['name'])){
    $do_upload=true;
  }
  if (!$data['user'] = $this->users_model->getUser($this->session->userdata('use_id'))){
    $data['vue_contenu'] = 'erreur';
    $data['details'] = 'Impossible de trouver la ressource demandée ('.$this->session->userdata('use_id').').';
  }
  else {
    //Nom des fichiers
    // $nom = 'agent_'.$data['user']->use_id.'-'.date('d-m-Y');
    $nom = 'agent_'.$data['user']->use_id.'-'.date('dmY');
    $extension = 'jpg';
    //Début de message d'erreur
    $msg_erreur = 'Des erreurs se sont produites lors de l\'envoi de votre photo.
';
    //Traitement upload
    if ($do_upload) {
      if ($_FILES['photo']['name']==null){
        $msg_erreur.='● Vous devez sélectionner une image à envoyer';
      }
      else {
        //On tente de supprimer les anciennes photos
        @unlink(BASE_PATH.'/trombi/'.REPUPLOAD.'/miniatures/'.$data['user']->use_photo);
        @unlink(BASE_PATH.'/trombi/'.REPUPLOAD.'/hd/'.$data['user']->use_photo);
      }
      $this->load->library('upload_class',$_FILES['photo']);
      $upload_miniature=false;
      if ($this->upload_class->uploaded) {
        $this->upload_class->file_new_name_body = $nom;
        $this->upload_class->file_new_name_ext = $extension;
        $this->upload_class->image_resize = true;
        $this->upload_class->image_x = 170;
        $this->upload_class->image_ratio_y = true;
        $this->upload_class->file_auto_rename = false;
        $this->upload_class->file_overwrite = true;
        $this->upload_class->file_safe_name = false;
        $this->upload_class->image_ratio_no_zoom_out = true;
        $this->upload_class->process(BASE_PATH . '/trombi/'.REPUPLOAD.'/miniatures/');
        if ($this->upload_class->processed) {
          //$this->upload_class->clean();
          $upload_miniature = true;
          $data_user = array(
          'use_id' => $this->session->userdata('use_id'),
          'use_photo' => $nom.'.'.$extension
          );
          $this->users_model->modifierUser($data_user);
        } else {
          $upload_miniature = false;
          $msg_erreur.= '● Echec lors du traitement de la miniature';
          $data['debug_miniature'] = $this->upload_class->error;
        }
      }
      $upload_hd=false;
      if ($this->upload_class->uploaded) {
        $this->upload_class->file_new_name_body = $nom;
        $this->upload_class->file_new_name_ext = $extension;
        $this->upload_class->image_resize = true;
        $this->upload_class->image_x = 470;
        $this->upload_class->image_ratio_y = true;
        $this->upload_class->file_auto_rename = false;
        $this->upload_class->file_overwrite = true;
        $this->upload_class->file_safe_name = false;
        $this->upload_class->image_ratio_no_zoom_out = true;
        $this->upload_class->process(BASE_PATH . '/trombi/'.REPUPLOAD.'/hd/');
        if ($this->upload_class->processed) {
          $this->upload_class->clean();
          $upload_hd = true;
        } else {
          $msg_erreur.= '
 ● Echec lors du traitement de la photo';
          $data['debug_hd'] = $this->upload_class->error;
        }
      }
      //Fin upload traitement des erreurs éventuelles
      if (!$upload_hd || !$upload_miniature) {
        $this->session->set_userdata('message',array('type'=>'error','texte'=>$msg_erreur));
      } else {
        $this->session->set_userdata('message',array('type'=>'success','texte'=>'Votre photo à été envoyée.'));
        redirect('profil/photo','refresh');
      }
    }
  }
  $this->load->view('includes/theme', $data);
}
Reply
Re: Resize image works with v030 but not with v0.34 new!
by colin, 6 years, 3 months ago
I am not sure why. You can output the log after calling process() to see what could be the issue.Reply
Re: Resize image works with v030 but not with v0.34 new!
by Patrice, 6 years, 2 months ago
Hello,

I try several solution, but no succes, I am not an experiment developer, sorry.
(and my english is so bad !

Reminder, the upload works fine for, but there is no resizing ?

This is the result of the log :

Erreur : system information
- class version : 0.35dev
- operating system : WINNT
- PHP version : 7.0.10
- GD version : 2.1.0
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- upload_max_filesize : 2M (2097152 bytes)
- language : en_GB
source is an uploaded file
- upload OK
- file name OK
determining MIME type
- Checking MIME type with Fileinfo PECL extension
MAGIC path defaults to C:\wamp64\bin\php\php7.0.10/extras/magic
Fileinfo PECL extension failed (finfo_open)
- Checking MIME type with UNIX file() command
UNIX file() command not availabled
- Checking MIME type with mime.magic file (mime_content_type())
MIME type detected as image/jpeg by mime_content_type()
- MIME validated as image/jpeg
source variables
- You can use all these before calling process()
file_src_name : moi2.jpg
file_src_name_body : moi2
file_src_name_ext : jpg
file_src_pathname : C:\wamp64\tmp\phpD1EF.tmp
file_src_mime : image/jpeg
file_src_size : 179820 (max= 2097152)
file_src_error : 0
- source file is an image
image_src_x : 470
image_src_y : 612
image_src_pixels : 287640
image_src_type : jpg
image_src_bits : 8
process file to C:\wamp64\www\loladev/trombi/praxiling/miniatures/\
- file size OK
- file mime OK : image/jpeg
- new file name body : agent_1-07-09-2018
- new file name ext : jpg
- destination variables
file_dst_path : C:\wamp64\www\loladev/trombi/praxiling/miniatures/\
file_dst_name_body : agent_1-07-09-2018
file_dst_name_ext : jpg
- no auto_rename if same filename exists
- destination file details
file_dst_name : agent_1-07-09-2018.jpg
file_dst_pathname : C:\wamp64\www\loladev/trombi/praxiling/miniatures/\agent_1-07-09-2018.jpg
- no overwrite checking
- EXIF data is invalid or missing
- image resizing or conversion wanted
- source image is JPEG
- setting destination file type to jpg
- resizing...
calculate y size
image_src_x y : 470 x 612
image_dst_x y : 170 x 221
cancel resizing, as it would shrink the image!
- converting...
fills in transparency with default color
- saving image...
JPEG image created
image objects destroyed
- process OK
process file to C:\wamp64\www\loladev/trombi/praxiling/hd/\
- file size OK
- file mime OK : image/jpeg
- new file name body : agent_1-07-09-2018
- new file name ext : jpg
- destination variables
file_dst_path : C:\wamp64\www\loladev/trombi/praxiling/hd/\
file_dst_name_body : agent_1-07-09-2018
file_dst_name_ext : jpg
- no auto_rename if same filename exists
- destination file details
file_dst_name : agent_1-07-09-2018.jpg
file_dst_pathname : C:\wamp64\www\loladev/trombi/praxiling/hd/\agent_1-07-09-2018.jpg
- no overwrite checking
- EXIF data is invalid or missing
- image resizing or conversion wanted
- source image is JPEG
- setting destination file type to jpg
- resizing...
calculate y size
image_src_x y : 470 x 612
image_dst_x y : 470 x 612
- converting...
fills in transparency with default color
- saving image...
JPEG image created
image objects destroyed
- process OK
cleanup
- delete temp file C:\wamp64\tmp\phpD1EF.tmpReply
Re: Resize image works with v030 but not with v0.34 new!
by colin, 6 years, 2 months ago
According to your logs:

The image is properly detected as image, with dimensions of 470x612

- MIME validated as image/jpeg
- source file is an image
image_src_x : 470
image_src_y : 612


The first image is created, but resizing doesn't happen because the created image would be smaller than the original image. Use image_ratio rather than image_ratio_no_zoom:

- file_dst_pathname : C:\wamp64\www\loladev/trombi/praxiling/miniatures/\agent_1-07-09-2018.jpg
- resizing...
calculate y size
image_src_x y : 470 x 612
image_dst_x y : 170 x 221
cancel resizing, as it would shrink the image!


The second image is created,but is not resized as the new image size would be the same as the old image size:

- file_dst_pathname : C:\wamp64\www\loladev/trombi/praxiling/hd/\agent_1-07-09-2018.jpg
- resizing...
calculate y size
image_src_x y : 470 x 612
image_dst_x y : 470 x 612
Reply