Resize after upload

Discuss MySQL Ajax Table Editor

Resize after upload

Postby vgnocchi » Sun Jul 11, 2010 1:12 pm

I am looking for a simple way to resize the image after upload to a fixed size (thumbnails), any ideas?
vgnocchi
 
Posts: 7
Joined: Sat Jul 10, 2010 5:09 am

Re: Resize after upload

Postby KarelB » Mon Jul 12, 2010 6:42 am

If you are using the paid version then you can see in example file UploadToDb.php a formatImage function.
To resize the image set the width and/or height attribute of the img tag.
KarelB
 
Posts: 458
Joined: Mon Dec 01, 2008 11:49 pm
Location: The Netherlands

Re: Resize after upload

Postby vgnocchi » Mon Jul 12, 2010 8:21 pm

Thanks Karen,

I am using the paid version, but I store the images to a directory, not to a db, is the same?
vgnocchi
 
Posts: 7
Joined: Sat Jul 10, 2010 5:09 am

Re: Resize after upload

Postby vgnocchi » Mon Jul 12, 2010 8:27 pm

Ok, I see it, but what I want is to resize the original size of the image, not the image tag of the editor.
vgnocchi
 
Posts: 7
Joined: Sat Jul 10, 2010 5:09 am

Re: Resize after upload

Postby KarelB » Mon Jul 12, 2010 9:24 pm

If you want to physically resize the image to a thumbnail size on upload you have to incorporate GD functions into the handleUpload function.

For example take a look at http://www.webcheatsheet.com/php/create_thumbnail_images.php and call this createThumbs function inside the handleUpload function. (This is just an example and there are many scripts that can do similar)
Hope this helps.
KarelB
 
Posts: 458
Joined: Mon Dec 01, 2008 11:49 pm
Location: The Netherlands

Re: Resize after upload

Postby admin » Mon Jul 12, 2010 9:41 pm

You could also use ImageMagicks convert command. I've found that to produce better quality images than the php gd functions. Here is part of a script that I created.
Code: Select all
// Resize the image
$outPut = array();
$returnVar = '';
exec('convert "'.$_FILES['item_file']['tmp_name'].'" -resize "x238" "'.$_FILES['item_file']['tmp_name'].'"',$outPut,$returnVar);
if($returnVar == 1)
{
   $valErrors[] = 'There was an error resizing the image.';
}
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Resize after upload

Postby vgnocchi » Wed Jul 14, 2010 3:16 pm

Thanks, works perfect!
vgnocchi
 
Posts: 7
Joined: Sat Jul 10, 2010 5:09 am

Re: Resize after upload

Postby cotsweb » Mon Jan 16, 2012 9:09 pm

If your host has PHP's Imagick extension installed (I think most do these days) you can call the Imagick class which is a nice tidy way of manipulating your image.

Code: Select all
function handleUpload($id,$col,$filesArr,$valErrors)
    {
        if(count($valErrors) == 0)
        {
            // Delete image file if the nurse already had one
            $query = "select image_file from nurses where nurse_id = '".$this->Editor->escapeData($id)."'";
            $result = $this->Editor->doQuery($query);
            if($row = mysql_fetch_assoc($result))
            {
                unlink($this->dataDir.$row['image_file']);
            }
            // Copy file to data directory and update database with the file name.
            if(move_uploaded_file($filesArr['tmp_name'],$this->dataDir.$filesArr['name']))
            {
                $query = "update nurses set image_file = '".$this->Editor->escapeData($filesArr['name'])."' where nurse_id = '".$this->Editor->escapeData($id)."'";
                $result = $this->Editor->doQuery($query);
                if(!$result)
                {
                    $valErrors[] = 'There was an error updating the database.';
                    unlink($this->dataDir.$filesArr['name']);
                }
            }
            else
            {
                $valErrors[] = 'The file could not be moved' . $filesArr['tmp_name'] . ' Name ' .$this->dataDir.$filesArr['name'] ;
                break;
            }
                //
                // Resize the image
                //
                if (!$image = new Imagick($this->dataDir.$filesArr['name'])) {
                    $valErrors[] = 'Unable to start Imagick';
                    return $valErrors;
                }
                if (!$image->scaleImage(200, 0)) {
                    $valErrors[] = 'Unable to scale image with Imagick';
                    return $valErrors;
                }
                if (!$image->writeImage($this->dataDir.$filesArr['name'])){
                    $valErrors[] = 'Unable to write scaled image with Imagick';
                    return $valErrors;
                }
        }
        return $valErrors;
    }

I hope somebody finds this useful.
cotsweb
 
Posts: 18
Joined: Mon Feb 28, 2011 12:38 pm

Re: Resize after upload

Postby thehrushi » Tue Jun 12, 2018 3:21 pm

I'm using the pro version, and using the upload to Db as my template. How do I resize images before uploading to Db? I want to keep the Db size low.
thehrushi
 
Posts: 7
Joined: Fri May 04, 2018 10:06 pm


Return to Open Discussion

Who is online

Users browsing this forum: Google [Bot] and 10 guests

cron