Re: Is There a Way to Automatically Reduce the Size of an Image During the Upload Process?

  •  07-29-2011, 6:55 AM

    Re: Is There a Way to Automatically Reduce the Size of an Image During the Upload Process?

    Hi LenJacobson,
     
    For now, can not achieve it at the uploading progress, you should change the size after upload success by other code.
     
    The example below shows you how to create a  thumbnail in the save folder after uploaded. hope it help.
     
    <?php require_once "phpuploader/include_phpuploader.php" ?>
    <?php session_start(); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>
    example
        </title>
    </head>
    <body>
     
                <form id="form1" method="POST">
                    <?php                
                        $uploader=new PhpUploader();
                        $uploader->MaxSizeKB=10240;
                        $uploader->Name="myuploader";
                        $uploader->InsertText="Select multiple files (Max 10M)";
                        $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif";    
                        $uploader->MultipleFilesUpload=true;
                        $uploader->Render();
                        
                        
                        
                function PhpGallery_Impl_LoadImage($imagefile)
                    {
                    $ext=pathinfo($imagefile,PATHINFO_EXTENSION);
                    switch(strtolower($ext))
                    {
                    case "png":
                    return imagecreatefrompng($imagefile);
                    case "gif":
                    return imagecreatefromgif($imagefile);
                    case "jpg":
                    case "jpeg":
                    default:
                    return imagecreatefromjpeg($imagefile);
                    }
                    }
                function PhpGallery_GenerateThumbnail($imagefile,$thumbpath,$width,$height)
                {
                $img=PhpGallery_Impl_LoadImage($imagefile);
                $thumb=imagecreatetruecolor($width,$height);
                imagecopyresized($thumb,$img,0,0,0,0,$width,$height,imagesx($img),imagesy($img));
                imagejpeg($thumb,$thumbpath);
                imagedestroy($img);
                imagedestroy($thumb);
                }
                ?>
        </form>
                
            
    <?php
    $fileguidlist=@$_POST["myuploader"];
    if($fileguidlist)
    {
    $guidlist=split("/",$fileguidlist);     
    $path="D:/2005/phpuploader/Photos/";
        foreach($guidlist as $fileguid)    
        {    
        
            $mvcfile=$uploader->GetUploadedFile($fileguid);       
            if($mvcfile)       
            {       
            $mvcfile->MoveTo($path.$mvcfile->FileName);
            PhpGallery_GenerateThumbnail($path.$mvcfile->FileName,$path."thumbnail".$mvcfile->FileName,128,128);
            }    
        }    
        }
    ?>
                    
        </div>
    </body>
    </html>
     
     
    Regards,
     
    ken
View Complete Thread