Welcome Guest, Not a member yet? Register   Sign In
Replace uploaded image with resized version..NEW PROBLEM: Uploaded url different than sql inserted url.
#1

[eluser]ColinHoernig[/eluser]
NEW PROBLEM, LAST POST!

So, I have my image upload working with thumbnail creation. This is how i have my upload method setup:
Code:
function _do_upload($field_name) {
        $config['upload_path'] = './img/products/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '2048';
        $config['max_width'] = '1600';
        $config['max_height'] = '1200';
        
        $this->load->library('upload', $config);
        
        if(!$this->upload->do_upload($field_name)) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('administration/products/add_product', $error);
        } else {
            $data = array('upload_data' => $this->upload->data());
            
            $temp = $this->upload->data();
            
            $config['image_library'] = 'GD2';
            $config['source_image'] = './img/products/' . $temp['file_name'];
            $config['maintain_ratio'] = TRUE;
            $config['create_thumb'] = TRUE;
            $config['quality'] = '80';
            $config['height'] = '100';
            $config['width'] = '100';
            
            $this->load->library('image_lib', $config);
            $this->image_lib->resize();
            
            $data = array('upload_data' => $this->upload->data());
            return $data;
        }
    }

It works to create the thumbnail and upload the original file, but what I want to do is upload a file, have it resize to set dimensions, and then replace the original file with the resized version.

Is this possible?

Also, is there a better way to get the thumbnail url from the upload? This is what I'm using now (it works but...):

Code:
// CUT OFF
$upload = $this->_do_upload('product_image');
        
        if($upload != NULL) {
            $product_image_url = $_FILES['product_image']['name'];
            $pos1 = strpos($product_image_url, ".");
            $file_type = substr($product_image_url, $pos1);
            $product_thumb_url = substr($product_image_url, 0, $pos1);
            $product_thumb_url .= "_thumb";
            $product_thumb_url .= $file_type;
//CUT OFF

I really appreciate anybodys help Smile.

So, I have my image upload working with thumbnail creation. This is how i have my upload method setup:
Code:
function _do_upload($field_name) {
        $config['upload_path'] = './img/products/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '2048';
        $config['max_width'] = '1600';
        $config['max_height'] = '1200';
        
        $this->load->library('upload', $config);
        
        if(!$this->upload->do_upload($field_name)) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('administration/products/add_product', $error);
        } else {
            $data = array('upload_data' => $this->upload->data());
            
            $temp = $this->upload->data();
            
            $config['image_library'] = 'GD2';
            $config['source_image'] = './img/products/' . $temp['file_name'];
            $config['maintain_ratio'] = TRUE;
            $config['create_thumb'] = TRUE;
            $config['quality'] = '80';
            $config['height'] = '100';
            $config['width'] = '100';
            
            $this->load->library('image_lib', $config);
            $this->image_lib->resize();
            
            $data = array('upload_data' => $this->upload->data());
            return $data;
        }
    }

It works to create the thumbnail and upload the original file, but what I want to do is upload a file, have it resize to set dimensions, and then replace the original file with the resized version.

Is this possible?

Also, is there a better way to get the thumbnail url from the upload? This is what I'm using now (it works but...):

Code:
// CUT OFF
$upload = $this->_do_upload('product_image');
        
        if($upload != NULL) {
            $product_image_url = $_FILES['product_image']['name'];
            $pos1 = strpos($product_image_url, ".");
            $file_type = substr($product_image_url, $pos1);
            $product_thumb_url = substr($product_image_url, 0, $pos1);
            $product_thumb_url .= "_thumb";
            $product_thumb_url .= $file_type;
//CUT OFF

I really appreciate anybodys help Smile.
#2

[eluser]srisa[/eluser]
$config['create_thumb'] = FALSE;
image lib documentation Scroll to where it says Resizing the original image.
#3

[eluser]ColinHoernig[/eluser]
[quote author="srisa" date="1230077543"]$config['create_thumb'] = FALSE;
image lib documentation Scroll to where it says Resizing the original image.[/quote]

I'm not sure if that's correct, as I still want to create the thumbnail, I just don't want to keep the original image, I want it replaced with a resized (but not thumbnail) version.

Maybe I misunderstood, but I appreciate it Smile.
#4

[eluser]srisa[/eluser]
Straight from the manual
Quote:Resizing the Original Image

If neither of the two preferences listed above (create_thumb, and new_image) are used, the resizing function will instead target the original image for processing.
If I understand that correctly, image will be resized; no new file,no thumb nail.
#5

[eluser]ColinHoernig[/eluser]
[quote author="srisa" date="1230133881"]Straight from the manual
Quote:Resizing the Original Image

If neither of the two preferences listed above (create_thumb, and new_image) are used, the resizing function will instead target the original image for processing.
If I understand that correctly, image will be resized; no new file,no thumb nail.[/quote]

Still, I'm not so sure this is what I'm looking for..

I have tried that and it hasn't worked. What I want is to make a thumbnail and a resized image from the original image. Once the two new images are created I want the original deleted, so to keep only the resized version and thumbnail.

As of right now I can only get one of either working, not both. I can either have it resized and be left with the original image, or have a thumbnail created and be left with it and the original image.
#6

[eluser]srisa[/eluser]
Sorry, I misunderstood. From what I understand you can either create thumbnail or resize the original at one time, not both at the same time. What you can do is, create the thumbnail first. Then reset the config items and do the resizing. You can clear the clear the config items with $this->image_lib->clear(); and then load new config with $this->image_lib->initialize($config);
#7

[eluser]ColinHoernig[/eluser]
[quote author="srisa" date="1230251208"]Sorry, I misunderstood. From what I understand you can either create thumbnail or resize the original at one time, not both at the same time. What you can do is, create the thumbnail first. Then reset the config items and do the resizing. You can clear the clear the config items with $this->image_lib->clear(); and then load new config with $this->image_lib->initialize($config);[/quote]

That worked great! Thanks a lot.

Now..how do I go about getting the actual link to the image to put that into the database. Right now its uploading with names like product_name_here.jpg and inserting names like product name here.jpg. Is there a way to get the correct upload name?
#8

[eluser]srisa[/eluser]
You can save a lot of time by reading the documentation. Data related to uploaded file is obtained with $this->upload->data();




Theme © iAndrew 2016 - Forum software by © MyBB