社区
基础编程
帖子详情
为何用PHP加GD库做出的缩略图颜色很差
wtboy
2004-01-29 03:02:55
看起来只有256色
...全文
126
7
打赏
收藏
举报
写回复
7 条
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wtboy
2004-01-31
OK:)
打赏
举报
回复
赞
dragonblue
2004-01-31
imagecreatetruecolor 我试了,OK
我的问题解决了,嘿嘿;沾了楼主的光
打赏
举报
回复
赞
wtboy
2004-01-29
gd
GD Support enabled
GD Version bundled (2.0.12 compatible)
FreeType Support enabled
FreeType Linkage with freetype
GIF Read Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
要这个做什么
GD2和GD1不能同时打开
打赏
举报
回复
赞
dragonsdg3
2004-01-29
up
顺便请教
能把你的phpinfo 中的configure
贴出来吗?
我的gd一直没配置成功!
打赏
举报
回复
赞
xuzuning
2004-01-29
gd2 ?
请使用imagecreatetruecolor建立目标图
if(function_exists("imagecreatetruecolor"))
$im = imagecreatetruecolor($width,$height); // 创建目标图 gd2
else
$im = imagecreate($width,$height); // 创建目标图 gd
打赏
举报
回复
赞
wtboy
2004-01-29
t
打赏
举报
回复
赞
ironage
2004-01-29
试试这段代码
(转自phpx.com)
<?
$FILENAME="image_name";
// 生成图片的宽度
$RESIZEWIDTH=400;
// 生成图片的高度
$RESIZEHEIGHT=400;
function ResizeImage($im,$maxwidth,$maxheight,$name){
$width = imagesx($im);
$height = imagesy($im);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$RESIZEWIDTH=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$RESIZEHEIGHT=true;
}
if($RESIZEWIDTH && $RESIZEHEIGHT){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($RESIZEWIDTH){
$ratio = $widthratio;
}elseif($RESIZEHEIGHT){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("imagecopyresampled")){
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
ImageJpeg ($newim,$name . ".jpg");
ImageDestroy ($newim);
}else{
ImageJpeg ($im,$name . ".jpg");
}
}
if($_FILES['image']['size']){
if($_FILES['image']['type'] == "image/pjpeg"){
$im = imagecreatefromjpeg($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/x-png"){
$im = imagecreatefrompng($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/gif"){
$im = imagecreatefromgif($_FILES['image']['tmp_name']);
}
if($im){
if(file_exists("$FILENAME.jpg")){
unlink("$FILENAME.jpg");
}
ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME);
ImageDestroy ($im);
}
}
?>
<img src="<? echo($FILENAME.".jpg?reload=".rand(0,999999)); ?>"><br><br>
<form enctype="multipart/form-data" method="post">
<br>
<input type="file" name="image" size="50" value="浏览"><p>
<input type="submit" value="上传图片">
</form>
</body>
</html>
打赏
举报
回复
赞
相关推荐
php
的
gd
颜色
不对,
php
-
PHP
GD
调色板
颜色
- 堆栈内存溢出
检查imagecolorstotal的返回值,无论您设置多少要抖动的
颜色
数量,总是得到256种
颜色
作为返回。 PNG-8和GIF格式仅支持最多256种
颜色
的调色板。 因此,即使您可以在调色板中使
用
超过256个,您也必须将其保存为真正的
颜色
,以便任何人都可以使
用
它,从而使整个转换过程浪费时间。 换句话说, imagetruecolortopallete的上限为256色,你不能更高。这是你如何在...
php
上传图片生成
缩略图
(
GD
库
)
首先来一段简单的
php
上传图片生成
缩略图
的详细代码,分享给大家供大家参考,具体内容如下 <?
php
function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality){ $details = getimagesize("$imageDirectory/$imageName") or die('Please only upload images.'); $type = preg_replace('@^.+(?<=/)(.+)$@', '$1', $details['mime'
php
使
用
GD
库
加
水印和
缩略图
imagecreatefrom* 图片载入函数imagecreatefromgifimagecreatefromjpegimagecreatefrompngimagecreatefromwbmpimagecreatefromstring如:imagecreatefromgif(
php
100.gif);imagecopy 图片合并函数imagecopy ( Dimg, Simg, i
使
用
PHP
GD
库
生成
缩略图
$filename = "test.jpg"; //文件名 $src_image = imagecreatefromjpeg($filename); //创建一个JEPG的画布资源 list($src_w, $src_h) = getimagesize($filename); //根据数组得到想要的宽高 $scale = 0.5; //缩放比例
php
上传图片仍然输出以前的,
php
上传图片生成
缩略图
(
GD
库
)
这篇文章主要介绍了
php
上传图片生成
缩略图
,还阐述了利
用
GD
库
上传图片以及创建
缩略图
,感兴趣的小伙伴们可以参考一下首先来一段简单的
php
上传图片生成
缩略图
的详细代码,分享给大家供大家参考,具体内容如下function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality){$detai...
发帖
基础编程
微信扫一扫
点击复制链接
分享社区
2.1w+
社区成员
14.0w+
社区内容
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
加入社区
帖子事件
创建了帖子
2004-01-29 03:02
社区公告
暂无公告