资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

phpGD库的使用

 $width ) {
    $dstHeight = $srcH * ($width / $srcW);
    // 新建一个真彩***像
    $dst = p_w_picpathcreatetruecolor( $width, $dstHeight );
    p_w_picpathcopyresampled($dst, $src,  0, 0, 0, 0, $width, $dstHeight, $srcW, $srcH);
    $src = $dst; 
    // 更新原图的宽度和高度
    $srcW = $width;
    $srcH = $dstHeight;
  }
  else {
    // 没有调整宽度
    $width = $srcW;
  }
  
  // 图片的高度大于$height切成多张图片
  if( $srcH > $height ) {
    // 切割的高度位置
    $srcY = 0;
    do {
      $dstHeight = ($srcY + $height > $srcH) ? ($srcH - $srcY) : ($height);
      $dst = p_w_picpathcreatetruecolor( $width, $dstHeight );
      p_w_picpathcopyresampled($dst, $src,  0, 0, 0, $srcY, $width, $dstHeight, $width, $dstHeight);
      $filePath = './img/' . md5(microtime(true)) . '.jpg';
      $imgPaths[] = $filePath;
      ImageJpeg($dst, $filePath);
      is_resource($dst) and p_w_picpathdestroy($dst);
      $srcY += $dstHeight;
    }while($srcY < $srcH);
  }
  else {
    // 如果高度符合 则将调整了原图(也有可能是调整了宽度之后的)保存为文件
    $filePath = './img/' . md5(microtime(true)) . '.jpg';
    $imgPaths[] = $filePath;
    ImageJpeg($src, $filePath);
  }

  // 释放内存
  isset($src) and is_resource($src) and p_w_picpathdestroy($src);
  isset($dst) and is_resource($dst) and p_w_picpathdestroy($dst);

  return $imgPaths;
}

/**
 * 调整图片清晰度
 * @param string $path  图片路径
 * @param string $quality 清晰度
 * @return string 新的图片路径
 */
function reQuality( $path, $quality ) {
    $p_w_picpath_type = p_w_picpath_type_to_extension(exif_p_w_picpathtype($path), false);
    $fun = "p_w_picpathcreatefrom{$p_w_picpath_type}";
    $src = $fun($path);
    $newPath = generateUniqueFilePath('./img/');
    ImageJpeg($src, $newPath, $quality);
    return $newPath;
}

/**
 * 生成唯一的文件路径
 * @param $basePath string 文件夹路径
 * @param $suffix string
 * @return string 文件路径
 */
function generateUniqueFilePath($basePath, $suffix='.jpg') {
  $filePath = $basePath . md5(microtime(true)) . $suffix;
  return $filePath;
}

header('Content-Type:p_w_picpath/png');

$path = './img/jjj.jpg';
$imgPaths = imgResize($path, 10000, 10000);
// reQuality($path, 1);

当前标题:phpGD库的使用
网页URL:http://cdkjz.cn/article/gishid.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220