gd(with jpeg支持)函数库,想更方便就使用ImageMagick
下载地址http://studio.imagemagick.org/script/download.php

解决方案 »

  1.   

    $im = imagecreatefromjpeg("s.jpg"); 
    $newim = imagecreatetruecolor(150,113);
    imagecopyresampled($newim, $im, 0, 0, 0,0,150,113,500,375);
    ImageJpeg($newim,"d.jpg"); 
    ImageDestroy($newim);
      

  2.   

    楼主看看Image 图像函数吧
    手册上都有
      

  3.   

    遍历目录中文件的类<?php
    class listfile{
    var $path=null;
    var $fileFunc=null; //文件操作函数,用于execute里的调用
    var $dirFunc=null; //目录操作函数
    var $tag = 0; //tag 0,处理文件,1,处理目录,2,既处理文件也处理目录。
    var $deep = 1;//目录深度,为1,表示第一层。
    var $filterPath=''; //过滤的目录
    var $extname=null; //有效文本文件的扩展名。function listfile()
    {
    echo 'initialize filetree<BR>';
    } // end funcfunction start(){
    $current = $this->path;
    //\0、\a、\b、\f、\n、\r、\t 和 \v
    $current = str_replace("\\", "/", $current);
    $current = preg_replace("/\/+/", "/", $current);
    $current = preg_replace("/\/$/", "", $current);
    $this->execute($current);
    }/** 函数 execute( $dirName = null )
    * 功能 对目录下所有文件及子目录下所有文件进行操作
    * 参数 $dirName 目录名称
    */
    function execute( $dirName = null ,$dirdeep = 1) 
    {
    if( empty( $dirName ) )
    exit( "IBFileSystem: directory is empty." );if( is_dir( $dirName ) )
    {
    if( $dh = opendir( $dirName ) )
    {
    while( ( $file = readdir( $dh ) ) !== false )
    {
    if( $file != "." && $file != ".." )
    {
    $filePath = $dirName . "/" . $file;
    if( is_dir( $filePath ) )//为目录,递归
    {

    $pos = strpos($this->filterPath,$file);
    if ($pos===false) {
    $this->execute( $filePath ,$dirdeep);
    }
    else {
        
    }    }
    else//为文件,进行处理
    {
    //如果包括全部文件
    if ($this->extname=="*") {
    eval($this->fileFunc); //echo"{$filePath}";echo"\n"; 
    }
    else {
    $dotpos = strrpos($file,"."); 
    if ($dotpos!==false) {
    $extname = substr($file,$dotpos+1);
    $pos = strpos($this->extname,$extname);
    if ($pos!==false) {
    eval($this->fileFunc); //echo"{$filePath}";echo"\n"; 
    }
    }     
    }    } //文件处理结束
    }
    }
    closedir( $dh );}
    else
    {
    exit( "IBFileSystem: can not open directory $dirName.");
    }//返回当前的$tree
    //return $tree;
    }else
    {
    exit( "IBFileSystem: $dirName is not a directory.");
    }
    }//</listDirTree>/** 
    * mkdirp is used to instead of mkdir ,mkdirp can create deep multiple directory.
    */
    function mkdirp($target) {
      // If the path already exists && is a directory, all is well.
      // If the path is not a directory, we've a problem.
      if (file_exists($target)) {
       if (!is_dir($target)) return false;
       else return true;
      }  // Attempting to create the directory may clutter up our display.
      if ( @mkdir($target) ) return true;  // If the above failed, attempt to create the parent node, then try again.
      if ( $this->mkdirp(dirname($target)) ) return $this->mkdirp($target);  return false;
    }//</function mkdirp>function help(){
    $help = <<<EOD
    \$fl = new listfile();
    \$fl->extname ="htm html css js"; //扩展名之间用空格隔开
    \$fl->tag = 2; //列出所有子目录,处理所有目录和文件,为1仅处理目录,为0仅处理文件。
    \$fl->path='D:/web/mambog_corp/tmp/ywjs';
    \$fl->filterPath='_vti_cnf'; //过滤目录
    \$fl->fileFunc = "echo(\\\$filePath.\"<br>\\n\");";
    \$fl->start();
    EOD;
    return $help;
    }//end func}//</class listfile>/*
    //examples
    $fl = new listfile();
    $fl->extname ="htm html css js"; //扩展名之间用空格隔开
    $fl->tag = 2; //列出所有子目录,处理所有目录和文件,为1仅处理目录,为0仅处理文件。
    $fl->path='D:\web\mambog_corp\tmp\ywjs';
    $fl->filterPath='_vti_cnf';
    $fl->fileFunc = "echo(\$filePath.\"<br>\\n\");";
    $fl->start();
    $help=$fl->help();
    echot($help,600,300);
    */
    ?>
      

  4.   

    function miniature($image, $path='', $width=150, height=113) {
      $imgstream = file_get_contents($image);
      $im = imagecreatefromstring($imgstream);  $newim = imagecreatetruecolor($width, $height);
      imagecopyresampled($newim, $im, 0, 0, 0,0, $width, $height, imagesx($im), imagesy($im));
      if(empty($path)
        ImageJpeg($newim); 
      else
        ImageJpeg($newim, $path.basename($image)); 
      ImageDestroy($im);
      ImageDestroy($newim);
    }$rs = mysql_query('select pic from category');
    while(list($pic) = mysql_fetch_row($rs)) {
      if(file_exists($pic))
        miniature($pic, 'picture/');
    }
      

  5.   

    to xuzuning(唠叨) :用你写的程序但提示错误:Parse error: parse error, unexpected T_STRING, expecting '&' or T_VARIABLE or T_CONST in c:\appserv\www\dingding1\test1.php on line 3不知道怎么回事?我的程序是这样的:
    <?
    include("inc/connect_db.inc");
    function miniature($image, $path='', $width=150, height=113) {
      $imgstream = file_get_contents($image);
      $im = imagecreatefromstring($imgstream);  $newim = imagecreatetruecolor($width, $height);
      imagecopyresampled($newim, $im, 0, 0, 0,0, $width, $height, imagesx($im), imagesy($im));
      if(empty($path)
        ImageJpeg($newim); 
      else
        ImageJpeg($newim, $path.basename($image)); 
      ImageDestroy($im);
      ImageDestroy($newim);
    }$rs = mysql_query('select pic1 from product');
    while(list($pic) = mysql_fetch_row($rs)) {
      if(file_exists($pic))
        miniature($pic, 'picture/');
    }
    ?>
      

  6.   

    function miniature($image, $path='', $width=150, height=113) {
    ==>
    function miniature($image, $path='', $width=150, $height=113) {不好意思,漏了个$
      

  7.   

    嗯。这个我查出来了。不好意思。还有他说
    Parse error: parse error, unexpected T_STRING in c:\appserv\www\dingding1\test1.php on line 9
    就是    imagejpeg($newim); 有问题!
      

  8.   

    我的category表中pic的路径是这样的:/dingding/uploadimages/11408718801.jpg
      

  9.   

    if(empty($path)
    ===>
     if(empty($path))漏了个)
      

  10.   

    恩。谢谢。
    现在程序运行成功,但是picture文件夹中没有生成图片。是不是我路径问题,我的category表中pic的路径是这样的/dingding/uploadimages/11408718801.jpg
      

  11.   

    如果我没有猜错的话,应该是已经生成。
    生成的路径为:C:/dingding/uploadimages/11408718801.jpg
      

  12.   

    $rs = mysql_query('select pic1 from product');
    while(list($pic) = mysql_fetch_row($rs)) {
      if(file_exists($pic))
        miniature($pic, 'c:/appserv/www/dingding1/picture/');
    }如果我把if(file_exists($pic))改称if(!file_exists($pic))就在picture文件夹中生成两张黑色的图片。就是黑色什么都没有。大小为150*113。如果不改,就什么都没有生成!为什么“?
      

  13.   

    单独执行
    miniature('dingding/uploadimages/11408718801.jpg');
    看是否在浏览器中显示缩略图
      

  14.   

    好象最简单的方法是去下载一个ACDSee 把图片本地转换一下  方便 高效  呵呵