这个帖子里面说的问题的确很严重, 也许加个flash会很难, 但图片缩小不变形却只是几行代码的事, 就算有白边, 但至少能知道是什么图片.
下面是一个类中的一小部分代码, 把那几个if esle搞明白, 至少比现在要强一百倍.- $CreateFunction = "imagecreatefrom".($this->ext == 'jpg' ? 'jpeg' : $this->ext);
- $SaveFunction = "image".($this->ext == 'jpg' ? 'jpeg' : $this->ext);
- if (strtolower($CreateFunction) == "imagecreatefromgif"
- && !function_exists("imagecreatefromgif")) {
- $this->errno = 16;
- return false;
- } elseif (strtolower($CreateFunction) == "imagecreatefromjpeg"
- && !function_exists("imagecreatefromjpeg")) {
- $this->errno = 17;
- return false;
- } elseif (!function_exists($CreateFunction)) {
- $this->errno = 18;
- return false;
- }
-
- $Original = @$CreateFunction($this->savePath.$this->saveName);
- if (!$Original) {$this->errno = 19; return false;}
- $originalHeight = ImageSY($Original);
- $originalWidth = ImageSX($Original);
- $this->returninfo['originalHeight'] = $originalHeight;
- $this->returninfo['originalWidth'] = $originalWidth;
- if (($originalHeight < $this->thumbHeight
- && $originalWidth < $this->thumbWidth)) {
- // 如果比期望的缩略图小,那只Copy
- copy($this->savePath.$this->saveName,
- $this->savePath.$this->thumbPrefix.$this->saveName);
- } else {
- if( $originalWidth > $this->thumbWidth ){// 宽 > 设定宽度
- $thumbWidth = $this->thumbWidth ;
- $thumbHeight = $this->thumbWidth * ( $originalHeight / $originalWidth );
- if($thumbHeight > $this->thumbHeight){// 高 > 设定高度
- $thumbWidth = $this->thumbHeight * ( $thumbWidth / $thumbHeight );
- $thumbHeight = $this->thumbHeight ;
- }
- }elseif( $originalHeight > $this->thumbHeight ){// 高 > 设定高度
- $thumbHeight = $this->thumbHeight ;
- $thumbWidth = $this->thumbHeight * ( $originalWidth / $originalHeight );
- if($thumbWidth > $this->thumbWidth){// 宽 > 设定宽度
- $thumbHeight = $this->thumbWidth * ( $thumbHeight / $thumbWidth );
- $thumbWidth = $this->thumbWidth ;
- }
- }
- if ($thumbWidth == 0) $thumbWidth = 1;
- if ($thumbHeight == 0) $thumbHeight = 1;
- $createdThumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
- if ( !$createdThumb ) {$this->errno = 20; return false;}
- if ( !imagecopyresampled($createdThumb, $Original, 0, 0, 0, 0,
- $thumbWidth, $thumbHeight, $originalWidth, $originalHeight) )
- {$this->errno = 21; return false;}
- if ( !$SaveFunction($createdThumb,
- $this->savePath.$this->thumbPrefix.$this->saveName) )
- {$this->errno = 22; return false;}
- }
复制代码 |