Get XOOPS XOOPSXOOPS FAQFAQ ForumsForums NewsNews ThemesThemes ModulesModules
New Posts New Topics All Posts All Forums Index General Modules Themes Development International XOOPS.org

Search

Donat-O-Meter

Make donations with PayPal!
Stats
Goal: $100.00
Due Date: Jun 30
Gross Amount: $25.00
Net Balance: $23.57
Left to go: $76.43

Donations
Anonymous ($15)Jun-14
Anonymous ($10)Jun-10

Learn XOOPS Core

Local Support

Advertisement

XOOPS Code hosted on SourceForge

Cumulus Tag Cloud

2 2.5 2.6 3.0 2013 Abuse admin AntiHarvesting AntiMalUser AntiSpam API Beats billige black block Blocking Blocks blue Captcha cell Christmas chronolabs content Conversion demo Dictionary docek download Dresses editor evden eve facebook floor forms framework free herre Honeypot Human Hymn instant-zero IP jQuery kantor lamps Load log logger mobile module modules Monster mulberry MyAlbum-p newbb news online PageRank pandora Party Permissions pink Plugin Plunger pollos portal Prevention profile project Protector publisher REST Rights rmcommon Room sale security Server site Smarty Spam stem Studio tag tags tdmcreate template Theme themes Transaction User userlog website Whitepaper Wishcraft XFriendica xoops Xortify ZendFramework

New Users

Registering user

# 136111

dihogo_cassi

Welcome to XOOPS!




Bottom   Previous Topic   Next Topic  Register To Post



#1 Posted on: 2009/9/2 11:35 Thumbnail creation after/during upload
Ciao, there is a function in XOOPS 2.3.3 for making a thumbnail from uploaded image?

if no, this code is always valid?
http://dev.xoops.org/modules/xfsnippe ... type=snippet&snippet_id=1

tnx
Urban

Top

urbanspacema
Quite a regular
Quite a regular
Joined:
2004/9/19 15:25
From Italy
Group:
Registered Users
Posts: 265
(Show More) (Show Less)


#2 Posted on: 2009/9/4 9:37 Re: Thumbnail creation after/during upload
ok i solved and sharing the code.

the functions
function timemachine_createthumb($name$path$savepath$new_w=100$new_h=100$quality=80){

    
$savefile $savepath.$name;
    
$savepath $savefile;
    
    if(!
file_exists($savepath)){
        
            
// Get image location
            
$image_path $path ."/".$name;
            
            
// Load image
            
$img null;
            
$ext end(explode('.'$image_path));
            if (
$ext == 'jpg' || $ext == 'jpeg') {
                
$img = @imagecreatefromjpeg($image_path);
            } else if (
$ext == 'png') {
                
$img = @imagecreatefrompng($image_path);
            
// Only if your version of GD includes GIF support
            
} else if ($ext == 'gif') {
                
$img = @imagecreatefrompng($image_path);
            }
            
            
// If an image was successfully loaded, test the image for size
            
if ($img) {
            
                
// Get image size and scale ratio
                
$width imagesx($img);
                
$height imagesy($img);
                
$scale min($new_w/$width$new_h/$height);
            
                
// If the image is larger than the max shrink it
                
if ($scale 1) {
                    
$new_width floor($scale*$width);
                    
$new_height floor($scale*$height);
            
                    
// Create a new temporary image
                    
$tmp_img imagecreatetruecolor($new_width$new_height);
            
                    
// Copy and resize old image into new image
                    
imagecopyresized($tmp_img$img0000,
                                     
$new_width$new_height$width$height);
                    
imagedestroy($img);
                    
$img $tmp_img;
                }
            }
            
            
// Create error image if necessary
            
if (!$img) {
                
$img imagecreate($new_w$new_h);
                
imagecolorallocate($img,0,0,0);
                
$c imagecolorallocate($img,70,70,70);
                
imageline($img,0,0,$new_w,$new_h,$c2);
                
imageline($img,$new_w,0,0,$new_h,$c2);
            }
    
            
            
// output the image as a file to the output stream

            
Imagejpeg($img,$savepath,$quality);

    }
    return 
$savefile;
}


the upload
//Form birthday_img    
        
include_once XOOPS_ROOT_PATH."/class/uploader.php";
        
$uploaddir_birthday_img XOOPS_ROOT_PATH."/uploads/timemachine/birthday/birthday_img/";
        
$uploaddir_birthday_thumbs_img XOOPS_ROOT_PATH."/uploads/timemachine/birthday/birthday_thumbs_img/";
        
$uploader_birthday_img = new XoopsMediaUploader($uploaddir_birthday_img$xoopsModuleConfig["birthday_img_mimetypes"], $xoopsModuleConfig["birthday_img_size"], nullnull);

        if (
$uploader_birthday_img->fetchMedia("birthday_img")) {
            
$uploader_birthday_img->setPrefix(str_replace(" ","_",$_REQUEST["birthday_who"]));
            
$uploader_birthday_img->fetchMedia("birthday_img");
            if (!
$uploader_birthday_img->upload()) {
                
$errors $uploader_birthday_img->getErrors();
                
redirect_header("javascript:history.go(-1)",3$errors);
            } else {
                
$obj->setVar("birthday_img"$uploader_birthday_img->getSavedFileName());
                
                
//genero la thumbnail
                
$name $uploader_birthday_img->getSavedFileName();
                
$path $uploaddir_birthday_img;
                
$savepath =$uploaddir_birthday_thumbs_img;
                
                
$new_w $xoopsModuleConfig["birthday_img_thumb_width"];
                
$new_h $xoopsModuleConfig["birthday_img_thumb_height"];
                
$thumb timemachine_createthumb($name$path$savepath$new_w$new_h$quality=80);
            }


note
$xoopsModuleConfig["birthday_img_thumb_width"] and other, are in my module preferences.

Top

urbanspacema
Quite a regular
Quite a regular
Joined:
2004/9/19 15:25
From Italy
Group:
Registered Users
Posts: 265
(Show More) (Show Less)


#3 Posted on: 2010/11/13 17:53 Re: Thumbnail creation after/during upload
As derya pointed out in the code snippet comments
Quote:
Should be better to use imagecopyresampled instead of imagecopyresized if your temp img is created with imagecreatetruecolor, because it keeps truecolor.

This makes a BIG difference to the thumbnail quality if they are any larger than an avatar.

Top


A thread is for life. Not just for Christmas.
Peekay
XOOPS is my life!
XOOPS is my life!
Joined:
2004/11/20 4:55
From UK
Group:
Registered Users
Posts: 2293
(Show More) (Show Less)







You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.

[Advanced Search]