Welcome Guest, Not a member yet? Register   Sign In
Resize and thumb
#1

[eluser]Thiago Leao[/eluser]
hi friends, i need help in resize and help.

UPLOAD_PRODUTO.php (View)

Code:
<?php
echo validation_errors();
echo form_open_multipart(base_url().'administracao/cad_produto/cad_img');
echo form_label('Foto do Produto', 'userfile');
echo "<input type=\"file\" name=\"userfile[]\" size=\"20\" class=\"multi\" />";
echo form_submit('mysubmit');
echo form_close();    
?>

CAD_PRODUTO (controller)

Code:
function cad_img(){
        
$data = date("Y-m");  
$dir = realpath('assets/uploads/'.$data.'/');

        
if(!is_dir($dir)){
mkdir($dir, 0777, TRUE);
}
        
$config['upload_path'] = realpath($dir);
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']    = '500'; // in kb
$config['max_width']  = '800';
$config['max_height']  = '600';
$config['encrypt_name'] = TRUE;
        
$this->load->library('upload', $config);
$this->load->library('Multi_upload');
        
$this->upload->initialize($config);        
$files = $this->multi_upload->go_upload();    
        
if ( ! $files ){
    $error = array('error' => $this->upload->display_errors());
    $this->load->view('administracao/upload_produto', $error);
}else{
$data = array('upload_data' => $files);
$this->load->view('administracao/upload_success', $data);
}
}

the upload is being done!
But I submit that the bigger picture and still allowed to send.

Another thing, I wanted to resize to 800x600 and 75x75 generate thumb, how? I've tried
everything looked the forum and can not.

Can anyone help me?
thanks
#2

[eluser]Thiago Leao[/eluser]
anyone pls?
thanks
#3

[eluser]mi6crazyheart[/eluser]
About that bigger image size problem i think u just check properly how much actually the bigger image size against the allowable size u've fixed in u'r config variable "$config['max_size']='500';(size in kilobytes)"...

And , about second the better approach is upload the image file 1st to a TEMPORARY folder then again try to move a copy from that temporary folder image by cropping it to u'r needed size. At last don't forget to delete the temporary folder image by PHP's unlink()...

Note: When u'll again upload image file from TEMPORARY folder to a new folder by cropping it (as in u'r case it width=800 & other one width="75") don't forget to use "$this->image_lib->clear();" just before u attempt to upload for 2nd time(when u'll attempt to upload image size for width='75')...


***Hope u've got the idea*** :coolsmile:
#4

[eluser]Thiago Leao[/eluser]
Well I found a code that serves me, is just missing one resize the original photo!!!

How to resize the picture right when you upload? and soon after creating the thumb???

thanks

Code:
<?php
class Uploader extends Controller {
  function go() {
    if(isset($_POST['go'])) {

      $config['upload_path'] = realpath('assets/uploads/'); /* NB! create this dir! */
      //echo print_r($config);
      $config['allowed_types']     = 'gif|jpg|png|bmp|jpeg';
      $config['max_size']      = '0';
      $config['max_width']      = '0';
      $config['max_height']      = '0';
     $config['encrypt_name']      = TRUE;
      
      /* Load the upload library */
      
      $this->load->library('upload', $config);
      $this->upload->initialize($config);    

      /* Create the config for image library */
      /* (pretty self-explanatory) */
      $configThumb = array();
      $configThumb['image_library'] = 'gd2';
      $configThumb['source_image'] = '';
      $configThumb['create_thumb'] = TRUE;
      $configThumb['maintain_ratio'] = TRUE;

      $configThumb['width'] = 140;
      $configThumb['height'] = 210;
      /* Load the image library */
      $this->load->library('image_lib');

      /* We have 5 files to upload
       * If you want more - change the 6 below as needed
       */
      
      for($i = 1; $i < 6; $i++) {
        /* Handle the file upload */
        $upload = $this->upload->do_upload('image'.$i);
        /* File failed to upload - continue */
        if($upload === FALSE) continue;
        /* Get the data about the file */
        $data = $this->upload->data();

        $uploadedFiles[$i] = $data;
        /* If the file is an image - create a thumbnail */
        if($data['is_image'] == 1) {
          $configThumb['source_image'] = $data['full_path'];
          $this->image_lib->initialize($configThumb);
          $this->image_lib->resize();
        }
      }
    }
    /* And display the form again */
    $this->load->view('administracao/upload_produto');
  }
}
?&gt;

Code:
&lt;? echo form_open_multipart(base_url().'administracao/uploader/go'); ?&gt;
    &lt;input type="file" name="image1" /&gt;&lt;br />  
    &lt;input type="file" name="image2" /&gt;&lt;br />  
    &lt;input type="file" name="image3" /&gt;&lt;br />  
    &lt;input type="file" name="image4" /&gt;&lt;br />  
    &lt;input type="file" name="image5" /&gt;&lt;br />  
    &lt;input type="submit" name="go" value="Upload!!!" /&gt;  
    &lt;/form&gt;
#5

[eluser]mi6crazyheart[/eluser]
Great... :coolsmile:
#6

[eluser]Thiago Leao[/eluser]
[quote author="mi6crazyheart" date="1287161362"]Great... :coolsmile:[/quote]

is missing the big picture resize in, for example have to stay with 640x480 and 140x210 thumb!!

I wait help!
thanks
#7

[eluser]mi6crazyheart[/eluser]
[quote author="Thiago Leao" date="1287161651"][quote author="mi6crazyheart" date="1287161362"]Great... :coolsmile:[/quote]

is missing the big picture resize in

I wait help!
thanks[/quote]

Sorry, couldn't able to understand. Can u say clearly what's the problem... ?
#8

[eluser]Thiago Leao[/eluser]
Sorry my English is not very good!

I want to resize the picture so I uploaded it!!

resize = 640x480 (lack this)
thumb = 140x210 (this code is already doing!)

thanks!
#9

[eluser]WanWizard[/eluser]
The code clearly shows how to resize an image to 140x120. You also have the user guide that explains how the library works.
It should be very easy to add a resize to 640x480 to it.

If not, maybe you should try to improve your PHP skills first, instead of 'borrowing' someone else's work and hope it does the trick, and if not, ask us to fix it for you.
#10

[eluser]Thiago Leao[/eluser]
not a matter of "borrowing" is that I am new to CodeIgniter ...
I'm still get used.
I just want a way to open my mind, I'm not asking you anything!




Theme © iAndrew 2016 - Forum software by © MyBB