php 上传图片 压缩大小 怎么实现的?
谢谢 ,本人现在特想知道这个问题! 你向灾区人民捐款100元,我告诉你怎么实现 靠 我都捐了 貌类要用到某种组件吧?我也想知道!
期待高手!
[img]http://www.phpx.com/happy/images/common/sigline.gif[/img]
[url=http://www.xing79.com]JokeJoke[/url] 期待高手指点 gd2 时刻期待着高手指点 thanks i got it GD
[php]
/**
* Method resize
*/
protected function _resize($new_width = 0, $new_height = 0)
{
if ($new_width <=0 && $new_height <= 0)
{
// Just copy it
@copy($this->source_filename, $this->target_filename);
return;
}
if ($new_width <= 0)
{
$new_width = $new_height * $this->rate;
}
if ($new_height <= 0)
{
$new_height = $new_width / $this->rate;
}
$this->target_width = $new_width;
$this->target_height = $new_height;
$this->_prepare();
imagecopyresized($this->target_gd_obj, $this->source_gd_obj, 0, 0, 0, 0, $this->target_width, $this->target_height, $this->source_width, $this->source_height);
$this->_save();
}
[/php]
ImageMagick
[php]
/**
* Method thumbnail
* In new version of ImageMagick, this is just like resize, but it's more faster
*/
protected function _thumbnail($new_width = 0, $new_height = 0)
{
$this->target_width = $new_width;
$this->target_height = $new_height;
$option = '-thumbnail';
$param = $new_width . 'x' . $new_height;
if (!$new_width)
{
$param = 'x' . $new_height;
}
if (!$new_height)
{
$param = $new_width;
}
$this->cmd = $this->_gen_cmd($option, $param);
return $this->_exec_cmd();
}
/**
* Generate a command line to execute imagemagick command tool
*/
protected function _gen_cmd($option, $param = '')
{
// Must source and target
if (!$this->source_filename || !$this->target_filename)
{
return false;
}
// "convert" or "mogrify"
if ($this->source_filename == $this->target_filename)
{
$this->handler = $this->bin_mogrify;
$m_flag = true;
}
else
{
$this->handler = $this->bin_convert;
$m_flag = false;
}
$cmd_exec = true_path($this->bin_dir . '/' . $this->handler);
$cmd = $cmd_exec . (!$m_flag ? (' ' . $this->source_filename . ' ') : ' ') . $option . ' ' . $param . ' ' . $this->target_filename;
return $cmd;
}
/**
* Execute command
*/
private function _exec_cmd()
{
@exec($this->cmd);
if (file_exists($this->target_filename))
{
return true;
}
return false;
}
[/php]
MagickWand
[php]
/**
* Method resize
*/
protected function _resize($new_width = 0, $new_height = 0)
{
$this->target_width = $new_width;
$this->target_height = $new_height;
$rv = MagickReadImage($this->wand_obj, $this->source_filename);
if (!$rv)
{
return false;
}
$rv = MagickResizeImage($this->wand_obj, $new_width, $new_height, MW_TriangleFilter, 1);
if (!$rv)
{
return false;
}
$rv = MagickWriteImage($this->wand_obj, $this->target_filename);
return $rv;
}
[/php]
代码片段,剩下的自己看着办 搞点注释吧 真的有些看不懂。 [quote]原帖由 [i]ctrlming[/i] 于 2008-5-19 04:22 PM 发表
搞点注释吧 真的有些看不懂。 [/quote]
你给奶瓶捐100块钱 我给你翻译注释 他又没受灾。。不给。
奶瓶这个东西是可以把图片伸缩 而不是截取吧? 有人说要截取吗? 我问问 我要收藏不截取的。 thanks GD。。好强大。 thanks! naiping 有的时候自己想清楚你要做什么
如果你是电脑,你如何分布做
然后去找对应的函数,就可以慢慢解决了
页:
[1]

