佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 873|回复: 5

如何把上传的图片缩小在PHP?

[复制链接]
发表于 26-12-2006 04:46 PM | 显示全部楼层 |阅读模式
如何把上传的图片缩小在PHP?
我尝试找了...
可是没有效果...

请前辈们教导...
回复

使用道具 举报


ADVERTISEMENT

发表于 26-12-2006 04:54 PM | 显示全部楼层
原帖由 伪君子 于 26-12-2006 04:46 PM 发表
如何把上传的图片缩小在PHP?
我尝试找了...
可是没有效果...

请前辈们教导...


之前有人问过了,
还是不久前
回复

使用道具 举报

 楼主| 发表于 26-12-2006 05:04 PM | 显示全部楼层
我也爬了帖...
可是找不到...
或许我看漏了...
可以给我那个link吗?
回复

使用道具 举报

 楼主| 发表于 26-12-2006 06:24 PM | 显示全部楼层
$dir = getcwd();
       $fol = "/img/";
       $size = 100; // the thumbnail height
       $size2 = 160; // the thumbnail2 height
       $filedir = "$dir$fol" ; // the directory for the original image
       $thumbdir ="$dir$fol"; // the directory for the thumbnail image
       $prefix = 'small_'; // the prefix to be added to the original name
       $prefix2 = 'small2_'; // the prefix2 to be added to the original name
       $maxfile = '2000000';
       $mode = '0666';
       $userfile_name = $_FILES['image']['name'];
       $userfile_tmp = $_FILES['image']['tmp_name'];
       $userfile_size = $_FILES['image']['size'];
       $userfile_type = $_FILES['image']['type'];

           if ($userfile_type == "image/pjpeg" || $userfile_type == "" ){
            
               if (isset($_FILES['image']['name'])){
                   $prod_img = $filedir.$userfile_name;
                   $prod_img_thumb = $thumbdir.$prefix.$userfile_name;
                   $prod_img_thumb2 = $thumbdir.$prefix2.$userfile_name;
                  }
                  
               if (file_exists($prod_img_thumb)) {
                header("Location: add_product.php?filex=1&tid=$tid");
                exit();
            }
               
               
            $imgname = $prefix.$userfile_name;
               if ($userfile_type == "image/pjpeg"){
                   move_uploaded_file($userfile_tmp, $prod_img);
                   chmod ($prod_img, octdec($mode));
                   $sizes = getimagesize($prod_img);
                   $aspect_ratio = $sizes[1]/$sizes[0];  
                   if ($sizes[1] <= $size)
                   {
                       $new_width = $sizes[0];
                       $new_height = $sizes[1];
                   }else{
                       $new_height = $size;
                       $new_width = abs($new_height/$aspect_ratio);
                   }
                  
// create first image with height 100

                   $destimg=ImageCreateTrueColor($new_width,$new_height)
                       or die('Problem In Creating image');
                   $srcimg=ImageCreateFromJPEG($prod_img)
                       or die('Problem In opening Source Image');
                   ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg))
                       or die('Problem In resizing');
                   ImageJPEG($destimg,$prod_img_thumb,90)
                       or die('Problem In saving');
                   imagedestroy($destimg);
                  
                  
// create second image2 with height 160   
               
                      if ($sizes[1] <= $size2)
                   {
                       $new_width2 = $sizes[0];
                       $new_height2 = $sizes[1];
                   }else{
                       $new_height2 = $size2;
                       $new_width2 = abs($new_height2/$aspect_ratio);
                   }               
               
                   $destimg=ImageCreateTrueColor($new_width2,$new_height2)
                       or die('Problem In Creating image');
                   $srcimg=ImageCreateFromJPEG($prod_img)
                       or die('Problem In opening Source Image');
                   ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width2,$new_height2,ImageSX($srcimg),ImageSY($srcimg))
                       or die('Problem In resizing');
                   ImageJPEG($destimg,$prod_img_thumb2,90)
                       or die('Problem In saving');
                   imagedestroy($destimg);     
                  
                   // DELETE the Original image
                    unlink($prod_img);     
                   }

我用这个Code...
在Localhost在可以Run...
可是当我Run在网上时...
就Run不到了...
回复

使用道具 举报

发表于 26-12-2006 11:48 PM | 显示全部楼层
因为你还没有设定权限罢了。
回复

使用道具 举报

 楼主| 发表于 28-12-2006 11:59 AM | 显示全部楼层
可是我已经把Folder设定去"Public"了...
可是还是一样...
还是这个要用Code设权限?
回复

使用道具 举报

Follow Us
您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT


本周最热论坛帖子本周最热论坛帖子

ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 26-8-2025 02:59 PM , Processed in 0.125848 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表