ok i solved and sharing the code.
the functions
le="color: #000000"><?php 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, $img, 0, 0, 0, 0, $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
le="color: #000000"><?php //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"], null, null); 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.