imagepng功能不太起作用

编程入门 行业动态 更新时间:2024-10-24 00:29:32
本文介绍了imagepng功能不太起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

从我用来创建缩略图的脚本中得到以下错误消息

I get the following error message when from a script I'm using to create a thumbnail

警告:imagepng()[function.imagepng]:无法打开"Manga/One Piece/asd/Thumbnail"以进行编写:是/homez.380/mangasma/www/mangaUpload.php中的目录,位于第220行

Warning: imagepng() [function.imagepng]: Unable to open 'Manga/One Piece/asd/Thumbnail' for writing: Is a directory in /homez.380/mangasma/www/mangaUpload.php on line 220

多数民众赞成在导致错误的行

thats the line causing the error

imagepng($dst_img,$dir);

这是方法

function createthumb($source,$output,$new_w,$new_h) { $dirpos=strrpos($output,"/"); $dir= substr($output,0,$dirpos); if(!file_exists($dir)) { mkdir($dir); chmod($dir,0775); }else { chmod($dir,0775); } $ext=explode(".",$source); $ext=$ext[count($ext)-1]; $ext=strtolower($ext); if (preg_match("/jpg|jpeg/",$ext)){$src_img=imagecreatefromjpeg($source);} if (preg_match("/png/",$ext)){$src_img=imagecreatefrompng($source);} if (preg_match("/gif/",$ext)){$src_img=imagecreatefromgif($source);} echo $src_img; $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if (preg_match("/png/",$ext)) { imagepng($dst_img,$dir); } elseif (preg_match("/gif/",$ext)) { imagegif($dst_img,$dir); } elseif (preg_match("/jpg|jpeg/",$ext)) { imagejpeg($dst_img,$dir); } imagedestroy($dst_img); imagedestroy($src_img); return array("w"=>$thumb_w,"h"=>$thumb_h); }

推荐答案

$dir不应是文件夹,而应是文件的路径(即:$dir = 'Manga/One Piece/asd/Thumbnail/1.png';)

$dir shouldn't be a folder but a path to a file (ie: $dir = 'Manga/One Piece/asd/Thumbnail/1.png'; )

例如,在imagepng($dst_img,$dir);(以及imagegif和imagejpeg)之前,您可以添加一行:

For example, just before imagepng($dst_img,$dir); (and imagegif and imagejpeg), you can add a line :

$dir .= '/test.png';

使用函数时,可以/应该将输出文件名作为参数传递

As you're using a function, you can/should pass the output filename as a parameter

更多推荐

imagepng功能不太起作用

本文发布于:2023-11-01 02:23:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547981.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不太   功能   imagepng

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!