Welcome Guest, Not a member yet? Register   Sign In
Image resize + upload
#1

[eluser]clintonbeattie[/eluser]
Hi,

I am rushed with an app I have to build, otherwise I would have tried to attempt this myself, but I was wondering if anyone has detailed code for uploading an image, adding it's url to a database and creating a resized thumbnail?

A lot to ask for I know. Any help much appreciated.

Thanks,
C
#2

[eluser]Vi.[/eluser]
I have written Auto resize image last month. I have added this function to CI but I can not find. Here is PHP code;
Code:
<?php
/**
* @author PCoder
* @copyright 2009
* Auto Resized Image / Thumb
*/
function resize($dosya, $yukseklik, $genislik, $kalite)
{
    $boyut = GetImageSize($dosya);
     /* Get image Width and Height */
    $resim_genis = $boyut[0];
     /* Real image width */
    $resim_yuksek = $boyut[1];
     /* Real image height */
    if ($resim_genis > $resim_yuksek) {
         /* If width is bigger than height */
        $yeni_y = ceil(($genislik * $resim_yuksek) / $resim_genis);
        $yeni_x = $yukseklik;
    } else {
         /* If height is bigger than width */
        $yeni_y = ceil(($yukseklik * $resim_genis) / $resim_yuksek);
        $yeni_x = $genislik;
    }
    $image_p = imagecreatetruecolor($yeni_x, $yeni_y);
     /* Create image with new size */
    $image = imagecreatefromjpeg($dosya);
     /* Load file from server that defined */
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $yeni_x, $yeni_y, $resim_genis,
        $resim_yuksek);
     /* Entegret the new sized image with loaded file */
    imagejpeg($image_p, null, $kalite);
     /* Create JPG file */
    Header("Content-type: image/jpeg");
     /* Some browser don't display image, this header() function fix */
}
?>
and Here is function to use;
Code:
<?php
resize("logo.jpg",150,150,90);
?>

I hope, I can help.
#3

[eluser]pistolPete[/eluser]
You should have a look at the Image Manipulation Class and the File Uploading Class.

It does all you want with little code.
#4

[eluser]bobbybaboon[/eluser]
This tutorial was on Nettuts recently, although it doesn't create thumbnails for you:
http://net.tutsplus.com/tutorials/php/cr...deigniter/
#5

[eluser]NateL[/eluser]
Here's a script I've been working on.... bits and peices are pulled out, but you'll get the point. Most of it can be found in the user guide

Also note - to get my script working, I had to use a hack that cwt137 kindly submitted.

This is the controller:
Code:
class Upload extends Controller
{
function do_upload()
    {
        // Image configuration
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['overwrite'] = FALSE;
        $config['max_size'] = 2048;
        
        $this->load->library('upload', $config);
        
    
        if(!$this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload_form', $error);
        }
        else
        {
            
        
            $image = $this->upload->data();
            $data['image'] = "./uploads/".$image['file_name'];
            
            $config['image_library'] = 'gd2';
            $config['source_image'] = $data['image'];
            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            $config['width'] = 75;
            $config['new_image'] = "./uploads/".$image['file_name'];
            
            $this->load->library('image_lib', $config);
            
            $this->image_lib->resize();
            
            $data = array('upload_data' => $this->upload->data());
            
            $this->load->view('upload_success', $data);
            
        }
    }
}

the view is simply a form with an action that posts to do_upload

Code:
<?=form_open_multipart('admin/upload/do_upload');?>
#6

[eluser]clintonbeattie[/eluser]
I will be trying all these this weekend.

Thanks for the replies!!!

Will let you know how I get on.




Theme © iAndrew 2016 - Forum software by © MyBB