php 生成图片并保存片

PHP生成的图片如何保存  PHP code  
$targ_w = $targ_h = 150; //保存的图片的大小
$jpeg_quality = 90;
$src = '/image/abc.jpg';
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
header('Content-type: image/jpeg');
imagejpeg($dst_r,null,$jpeg_quality);
ImageDestroy($dst_r);
现在图片可以正常显示了1:但是如何自动保存在服务器abc123.jpg2:要想再保存个50*50的缩略图怎么做abc123456.jpg
回答1:不输出,保存为文件,只需修改 imagejpeg()的第二个参数为文件名,那么自然也不需要 Header()声明输出流。保存缩略图,参见 imagecopyresampled() 函数
1,bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )第二个参数指定文件。2,bool imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
snynixayyhphp 生成文字png图片的代码
字体:[ ] 类型:转载 时间:
使用GD生成文字图片是php一项比较常用的功能,笔者今天介绍的是生成文字png图片的函数。需要的朋友可以参考下。
代码如下: &? /* php生成文字png图片,可以使用如下方式调用函数: /text_png.php3?msg=helloworld+class&rot=15&size=48&font=fonts/ARIAL.TTF */ Header("Content-type: image/png"); class textPNG { var $font = 'fonts/TIMES.TTF'; //默认字体. 相对于脚本存放目录的相对路径. var $msg = "undefined"; // 默认文字. var $size = 24; var $rot = 0; // 旋转角度. var $pad = 0; // 填充. var $transparent = 1; // 文字透明度. var $red = 0; // 在黑色背景中... var $grn = 0; var $blu = 0; var $bg_red = 255; // 将文字设置为白色. var $bg_grn = 255; var $bg_blu = 255; function draw() { $width = 0; $height = 0; $offset_x = 0; $offset_y = 0; $bounds = array(); $image = ""; // 确定文字高度. $bounds = ImageTTFBBox($this-&size, $this-&rot, $this-&font, "W"); if ($this-&rot & 0) { $font_height = abs($bounds[7]-$bounds[1]); } else if ($this-&rot & 0) { $font_height = abs($bounds[1]-$bounds[7]); } else { $font_height = abs($bounds[7]-$bounds[1]); } // 确定边框高度. $bounds = ImageTTFBBox($this-&size, $this-&rot, $this-&font, $this-&msg); if ($this-&rot & 0) { $width = abs($bounds[4]-$bounds[0]); $height = abs($bounds[3]-$bounds[7]); $offset_y = $font_ $offset_x = 0; } else if ($this-&rot & 0) { $width = abs($bounds[2]-$bounds[6]); $height = abs($bounds[1]-$bounds[5]); $offset_y = abs($bounds[7]-$bounds[5])+$font_ $offset_x = abs($bounds[0]-$bounds[6]); } else { $width = abs($bounds[4]-$bounds[6]); $height = abs($bounds[7]-$bounds[1]); $offset_y = $font_; $offset_x = 0; } $image = imagecreate($width+($this-&pad*2)+1,$height+($this-&pad*2)+1); $background = ImageColorAllocate($image, $this-&bg_red, $this-&bg_grn, $this-&bg_blu); $foreground = ImageColorAllocate($image, $this-&red, $this-&grn, $this-&blu); if ($this-&transparent) ImageColorTransparent($image, $background); ImageInterlace($image, false); // 画图. ImageTTFText($image, $this-&size, $this-&rot, $offset_x+$this-&pad, $offset_y+$this-&pad, $foreground, $this-&font, $this-&msg); // 输出为png格式. imagePNG($image); } } $text = new textPNG; if (isset($msg)) $text-&msg = $ // 需要显示的文字 if (isset($font)) $text-&font = $ // 字体 if (isset($size)) $text-&size = $ // 文字大小 if (isset($rot)) $text-&rot = $ // 旋转角度 if (isset($pad)) $text-&pad = $ // padding if (isset($red)) $text-&red = $ // 文字颜色 if (isset($grn)) $text-&grn = $ // .. if (isset($blu)) $text-&blu = $ // .. if (isset($bg_red)) $text-&bg_red = $bg_ // 背景颜色. if (isset($bg_grn)) $text-&bg_grn = $bg_ // .. if (isset($bg_blu)) $text-&bg_blu = $bg_ // .. if (isset($tr)) $text-&transparent = $ // 透明度 (boolean). $text-&draw(); ?&
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具& 以 PNG 格式将图像输出到浏览器或文件
PHP imagepng 以 PNG 格式将图像输出到浏览器或文件
imagepng & 以 PNG 格式将图像输出到浏览器或文件
bool imagepng
( resource $image
[, string $filename
PHP imagepng note #1
The name "quality" for the compression parameter is quite misleading, as png compression is always lossless. The trade off is between speed and filesize, it cannot affect quality.
Here's something I fo I haven't checked it, but if it is correct it should definitely included in the documentation:
from php source (gd.h):
/* 2.0.12: Compression level: 0-9 or -1, where 0 is NO COMPRESSION at all,
* 1 is FASTEST but produces larger files, 9 provides the best
* compression (smallest files) but takes a long time to compress, and
* -1 selects the default compiled into the zlib library.
Conclusion: Based on the Zlib manual () the default compression level is set to 6.
Regarding suggestions to rescale the 0-99 quality range of jpeg into the 0-9 range of png, note that for jpeg 99 is minimum compression (maximum quality) while for png 9 is maximum compression (quality doesn't change).
PHP imagepng note #2
My script was unable to complete: Fatal error: Allowed memory size of XX bytes exhausted (tried to allocate XX+n bytes).
I found out that PHP handles images in uncompressed format: my input image was
bit =& ~150 MB per single in-memory copy.
As a solution, you can either check the dimensions and reject anything too big or, as I did, use ini_set('memory_limit','1024M'); on the page start (if your server has enough on board memory).
PHP imagepng note #3
If you care about speed, you probably already cache your generated images to a file. In that case, DON'T use "createimagefrompng" and "imagepng" to output the image. Use fpassthru instead. It is literally hundreds of times faster.
& header("Content-Type: image/png");
& if( !file_exists($cachefile) ) {
&&& $im = generateimage();& && imagepng($im, $cachefile); imagedestroy($im);
& $fp = fopen($cachefile, 'rb'); fpassthru($fp);
I've tested it with a
(1.2Mb) image, that was cached on the harddisk. Using imagepng, the transfer took 12 seconds. Using fpassthru, it took only 32ms!
PHP imagepng note #4
Creating a transparent image filled with tranparent color only
I had some hard times putting up this one:
$img = imagecreatetruecolor(100,100);
imagesavealpha($img, true);
$color = imagecolorallocatealpha($img,0x00,0x00,0x00,127);
imagefill($img, 0, 0, $color);
imagepng($img, "file.png");
imagedestroy($img);
PHP imagepng note #5
If you're generating an image dynamically based on post data and don't want to save it to the server, sending it to be displayed can cause problems as when the person tries to save it, the browser will request it again from the server (causing any post data to be lost and probably a corrupted png).
The easiest way to get around this is to force it to download using the content disposition header, for example:
header('Content-Disposition: Afilename=image.png');
header('Content-type: image/png');
PHP imagepng note #6
If you need to call imagepng() multiple times (for example, when you want to send it to the browser, but also to a disk cache), write your image to a file first, THEN call readfile() on it.
PHP internally works with a temporary file when sending the image to the browser, so you'll gain nothing by calling imagepng() twice.
PHP imagepng note #7
When you allow multiple output formats, (jpg/png) but want to use the 1-100 quality scale (like jpg), you will have to format the number:
$pngQuality = ($quality - 100) / 11.111111;
$pngQuality = round(abs($pngQuality));
imagepng($resource, $path, $pngQuality);
PHP imagepng note #8
I just lost about 4 hours on a really stupid problem. My images on the local server were somehow broken and therefore did not display in the browsers. After much looking around and testing, including re-installing apache on my computer a couple of times, I traced the problem to an included file.
No the problem was not a whitespace, but the UTF BOM encoding character at the begining of one of my inluded files...
So beware of your included files!
Make sure they are not encoded in UTF or otherwise in UTF without BOM.
Hope it save someone's time.
PHP imagepng note #9
I ran across the following WRT sessions and image creation.
In main.php:
& (...session in progress...)
& $_SESSION['text']='some text...';
& $imgSrc=''.session_id();
& echo('&img src="'.$imgSrc.'"/&');
& unset($_SESSION['text']);
In createImage.php:
& header('image/png');
& session_id($_REQUEST['sid']);
& session_start();
& $img=imagecreatetruecolor(200, 30);&
& $text_color=imagecolorallocate($img, 200, 200, 200);
& imagestring($img, 5, 5, 5,& $_SESSION['text'], $text_color);
& imagepng($img);
& imagedestroy($img);
Problem: main.php execution ends before createImage.php writing the text to image, thus the unset($_SESSION['text']) destroys the text and you end up with empty image.
Solution: move call to unset() as last statement of createImage.php
PHP imagepng note #10
To change the background of a 24-bit PNG for graceful degradation in IE6, the PNG file needs a bKGD chunk:
&&& $bgColor = array(250, 250, 250);
&&& $pngData = bin2hex(file_get_contents($filename));
&&& $idatMarker = '';
&&& $bkgdMarker = '624b4744';
&&& $bkgdChunk = '0006' . $bkgdMarker;
&&& foreach ($bgColor as $bit)
&& & && $bkgdChunkData .= '00' . dechex($bit);
&&& $bkgdChunk .= $bkgdChunkData;
&&& $bkgdChunk .= dechex(crc32(pack('H*', $bkgdMarker . $bkgdChunkData))) . '0000';
&&& $parsed = explode($idatMarker, $pngData, 2); $pngData = pack('H*', $parsed[0] . $bkgdChunk . $idatMarker . $parsed[1]);
&&& file_put_contents($cachedFilename, $pngData);
PHP imagepng note #11
&&& $marked_aid = 2403;
&&& $mysqlhost = 'localhost';
&&& $mysqluser = 'user';
&&& $mysqlpass = 'password';
&&& $mysqldb = 'database';
&&& $db = @mysql_connect($mysqlhost, $mysqluser, $mysqlpass) OR die('Can not connect to DB-Server!');
&&& $db_select = @mysql_select_db($mysqldb) OR die('Can not select DB!');
&&& $image = imagecreate(801, 801);
&&& $color_background = imagecolorallocate($image, 255, 255, 255);
&&& $color_normal = imagecolorallocate($image, 200, 200, 200);
&&& $color_marked = imagecolorallocate($image, 255, 0, 0);
&&& imagefill($image, 0, 0, $color_background);
&&& $query = 'SELECT x, y, aid FROM x_world ORDER BY id ASC';
&&& $result = @mysql_query($query) OR die('Can not select villages from table x_world!');
&&& if (mysql_num_rows($result)) {
&& & && $row = @mysql_fetch_assoc($result);
&& & && $x_pointer = 0;
&& & && $y_pointer = 0;
&& & && for($y=400; $y &= -400; $y--) {
&& & & & && for ($x=-400; $x &= 400; $x++) {
&& & & & & & & &
&& & & & & & && if ($row['x'] == $x AND $row['y'] == $y) {
&& & & & & & & & & &
&& & & & & & & & && if ($row['aid'] == $marked_aid) {
&& & & & & & & & & & && $color = $color_marked;
&& & & & & & & & && } else {
&& & & & & & & & & & && $color = $color_normal;
&& & & & & & & & && }
&& & & & & & & & & &
&& & & & & & & & && imagefilledrectangle($image, $x_pointer, $y_pointer, ($x_pointer + 1), ($y_pointer + 1), $color);
&& & & & & & & & & &
&& & & & & & & & && $row = @mysql_fetch_assoc($result);
&& & & & & & && }
&& & & & & & & &
&& & & & & & && $x_pointer++;
&& & & & && }
&& & & & & &
&& & & & && $y_pointer++;
&& & & & & &
&& & & & && $x_pointer = 0;
&& & && }& &&
&&& header("Content-Type: image/png");
&&& imagepng($image);
PHP imagepng note #12
If you want to open a png image with alpha blending, you need to do something like this:
$file = 'semitransparent.png'; $img = imagecreatefrompng($file); imagealphablending($img, true); imagesavealpha($img, true); ?&
I spent almost a day to find out why alpha blending doesn't work. I hope this is usefull to others too :)
PHP imagepng note #13
@ phpman at texmedia dot de:
The compression range in PNG is in range 0-9, i think if you specified a compression level higher than 9, it'll be completely "compressed", or suppressed in the other words.
The compression level is originally for JPEG, which is in range 0 - 100, I think it'll work fine if you divide it by ten before passing to imagepng(). ;)
PHP imagepng note #14
My webserver, running 5.14 didn't like the header that was generated using imagepng(). It works find on my local test server and on 4.x from another host.
The generated image displays in the browser (IE, firefox) but when saved to a file or inserted into an RTF file, the image was corrupted. As a test, when attempting to right-click to save as, the image format was not recognized.
The only work-around appears to be adding the additional paramaters.
So instead of just
imagepng($image); //DIDNT WORK--CORUPT IMAGE
This worked
imagepng($image,NULL,0,NULL);
and saving to disk, this worked:
imagepng($image,$file_location,0,NULL);
PHP imagepng note #15
When changeing the PHP version from 4 to 5 I found out, that PHP5 handles imagepng() more restrictive than in PHP4. I'd used
imagepng($image,'',90);
to reduce the image quality whithout saving the image as a file. The quality parameter is not supported at all, I used imagejpg before and simply changed the function to imagepng whithout taking care of the existing parameters. It did not matter and there was no error in PHP4. But in PHP5, the image will not be shown anymore. So you have to remove it to have the standard:
imagepng($image);
PHP imagepng note #16
barts code below does not work at least with gd 2
Only returns a blank image with alpha not the source resized
&& & && $im = ImageCreateFromPNG($sourcefile);
&& & && $im_dest = imagecreatetruecolor ($forcedwidth, $forcedheight);
&& & && imagealphablending($im_dest, false);
&& & && imagecopyresampled($im_dest, $im, 0, 0, 0, 0, $wm_width, $wm_height, $forcedwidth, $forcedheight);
&& & && imagesavealpha($im_dest, true);
&& & && imagepng($im_dest, $destfile);
&& & && imagedestroy($img_dest);
ps you also forgot image destroy and you had a random var in imagepng undefined in your post
PHP imagepng note #17
If you want to resize a png-24 image and preserve the alpha channel you need to set imagealphablending($im_dest, false) on the destination image just after creating it with imagecreatetruecolor() and do a imagesavealpha($im_dest, true) on it before saving it:
$im = ImageCreateFromPNG('redfade.png');
$im_dest = imagecreatetruecolor (500, 300);
imagealphablending($im_dest, false);
imagecopyresampled($im_dest, $im, 0, 0, 0, 0, 300, 300, 500, 300);
imagesavealpha($im_dest, true);
imagepng($im_re, 'small_redfade.png');
PHP imagepng note #18
Trying to resize a png 256 colors image and save it in 256 colors with a correct color palette ? (if you'll save a 256 color image in truecolor palette the result image will have a big size).
I spent some hours trying various function to get a good quality 256 color png image, but because of color palette the result image quality was awful.
But thank to the comment of zmorris at zsculpt dot com from imagetruecolortopalette function page, i figured out how to get a properly image!
function resize_png($src,$dst,$dstw,$dsth) {
&&& list($width, $height, $type, $attr) = getimagesize($src);
&&& $im = imagecreatefrompng($src);
&&& $tim = imagecreatetruecolor($dstw,$dsth);
&&& imagecopyresampled($tim,$im,0,0,0,0,$dstw,$dsth,$width,$height);
&&& $tim = ImageTrueColorToPalette2($tim,false,255);
&&& imagepng($tim,$dst);
function ImageTrueColorToPalette2($image, $dither, $ncolors) {
&&& $width = imagesx( $image );
&&& $height = imagesy( $image );
&&& $colors_handle = ImageCreateTrueColor( $width, $height );
&&& ImageCopyMerge( $colors_handle, $image, 0, 0, 0, 0, $width, $height, 100 );
&&& ImageTrueColorToPalette( $image, $dither, $ncolors );
&&& ImageColorMatch( $colors_handle, $image );
&&& ImageDestroy($colors_handle);
&&& return $image;
Good luck,
Namolovan Nicolae, Moldova
PHP imagepng note #19
PNG images (as any image) can be stored in a MySQL blob field, but if you want to do this, you'll want to serialize the image stream into a better form. I would recommend base64_encode() and base64_decode(). (Just fopen() the file, fread() the contents in, base64_encode() the string, and fire off your SQL query (use addslashes()/stripslashes() to be more secure)).
This has been posted an innumerable amount of times throughout the site, but it's still terrible that a lot of users simply don't understand this and use it to its full potential.
I would also recommend that if you are doing images this way, to keep an image cache folder somewhere that PHP can access (possibly even somewhere off your webroot?). That way if your website is swamped with traffic it won't kill the SQL server.
PHP imagepng note #20
To send 'Content-Length' header (like in static pictures case) i use "Output handler" like this...
function output_handler($img) {
&&& header('Content-type: image/png');
&&& header('Content-Length: ' . strlen($img));
&&& return $img;
ob_start("output_handler");
imagepng($im);
ob_end_flush();
PHP imagepng note #21
This is my way to store PNG-images in a MySQL database... You cannot directly store the PNG-image in a variable, and then parse it in the database, cos if you try to define it to a variable, it'll still just output it...
In my method i use three functions
&to "capture" the output and st ob_start (to start the output buffering),& & ob_get_contents& (to capture the output),& & and& ob_end_clean (to erase the cache, and end the output buffering)
$imagefile = "changethistogourimage.gif";
$image = imagecreatefromgif($imagefile);
ob_start();
imagepng($image);
$imagevariable = ob_get_contents();
ob_end_clean();
PHP imagepng note #22
You could use the function imagecreatefrompng
(I assume that you already know how to get the text from the url.)
The only thing left to do is put that text on the image using the correct colors for you.
$im = @imagecreatefrompng($imgname);
$text_color = imagecolorallocate ($im, $Red,$Green,$Blue);
imagestring ($im, 3,& 5, 15,& $SomeTextFromURL, $text_color);
Peter Berkhout.
PHP imagepng note #23
To cbrasho at yahoo dot com
I have read your note and the note that was made in reply. My SIMPLE solution is to add a key to each image record in the database so that the ID+Key pair will be used very similarly to a Username+Password pair =) all you have to do is create a unique random number or something to put in the "Key" field of the database when the entry is made.
i've modified the code and pasted it here...
$id = $_REQUEST['id'];
$key = $_REQUEST['key']; $sql = "SELECT Data, Type, Extension FROM Images WHERE ID=$id AND Key=$key"; $records=mysql_query($sql);
$record=mysql_fetch_row($records);
$data=$record['Data'];
$type=$record['Type'];
$ext=$record['Extension'];
header("Content-Type: $type");
header("Content-Disposition: filename=img$id.$ext");
echo $data;
all i did was add 1 line and change another =D
now if "image.php?id=1&key=A29F1X" gives a result, "image.php?id=2&key=A29F1X" will output an image of zero bytes in size because the keys in the database are unique =)
PHP imagepng note #24
Presumably it returns true on success and false on failure, although the documentation doesn't actually say so.
PHP imagepng note #25
To cbrasho at yahoo dot com
I don't get the problem. If you want to have images stored as blobs, you can do a show.php like this:
$id = $_REQUEST['id'];
$sql = "SELECT Data, Type, Extension FROM Images WHERE ID=$id";
$records=mysql_query($sql);
$record=mysql_fetch_row($records);
$data=$record['Data'];
$type=$record['Type'];
$ext=$record['Extension'];
header("Content-Type: $type");
header("Content-Disposition: filename=img$id.$ext");
echo $data;
I've done this many times (conceptually), and it works like a charm, although I would recommend a little more security on that indata. If you have a unified place images go in (like an upload form), you can even drop the type and extension part by saving every image as the same filetype.
PHP imagepng note #26
Having your pictures stored in a database sounds great but brings you a lot of trouble.
Storing images in a DB you will have a script show.php that will appear in &img& tags: &img src='show.php?img_id=$some_id'&
But if you want to have REGISTER GLOBALS = OFF, you are in trouble and there is no way (at leas as far as i know) to solve the problem but to put te img from the DB in a file and put the coresponding file name in the &img& tag. But this brings another problem: simultaneous accesses to the page. So you will have to find a way to give unique names to the picture files for each simultaneous access to the page. The solution might be using sessions. This is how you end up having a very compleh PHP script for a very simple problem. So, the basic ideea is " do not store your pictures in a blob unless you know exactly what you are doing".
PHP imagepng note #27
to all the ones, who like having their users fill their profil with an image without destroying a fixed design the following should be a great way to handle this problem.
this file opens a picture from $imagepath and returns it as a valid picture to embed in: &img src="file.php?image=123.jpg[?maxX=200&maxY=150]"& (in [] = optional)
but this file does more than this. it also adds black borders to files that are smaller than the max. size, so adding borders to the left and right where a image is too high :-)
if there is a need for a copyright note this script will also help you. you can put in a various text to $copyright. the text length should be in relationship to $maxX and $maxY.
Well there are other features of the script, just try'em out and have fun with it :-)
if(!isset($maxX)) $maxX = 100;
if(!isset($maxY)) $maxY = 75;
$picBG = "0,0,0"; $picFG = "104,104,104"; $copyright = "stefan bechtold";
$font = 1;
$minZoom = 1; $maxZoom = 200; $imgpath = "userimages/"; $nopicurl = "images/nopic.jpg"; $nofileurl = "images/nofile.jpg"; if(!isset($image) || empty($image))
&&& $imageurl = $imgpath . $nopicurl;
elseif(! file_exists($imgpath . trim($image)))
&&& $imageurl = $imgpath . $nofileurl;
&&& $imageurl = $imgpath . trim($image);
$image = getImageSize($imageurl, $info); switch($image[2]) {
&& && case 1:
&& & & $timg = imageCreateFromGIF($imageurl);
&&& case 2:
&& & & $timg = imageCreateFromJPEG($imageurl);
&&& case 3:
&& & & $timg = imageCreateFromPNG($imageurl);
$imgX = $image[0];
$imgY = $image[1];
$_X = $imgX/$maxX * 100;
$_Y = $imgY/$maxY * 100;
if((100-$_X) & (100-$_Y)) $_K = $_X;
else $_K = $_Y;
if($_K & 10000/$minZoom) $_K = 10000/$minZoom;
if($_K & 10000/$maxZoom) $_K = 10000/$maxZoom;
$newX = $imgX/$_K * 100;
$newY = $imgY/$_K * 100;
$posX = ($maxX-$newX) / 2;
$posY = ($maxY-$newY) / 2;
$imgh = imageCreateTrueColor($maxX, $maxY);
$cols = explode(",", $picBG);
$bgcol = imageColorallocate($imgh, trim($cols[0]), trim($cols[1]), trim($cols[2]));
$cols = explode(",", $picFG);
$fgcol = imageColorallocate($imgh, trim($cols[0]), trim($cols[1]), trim($cols[2]));
imageFill($imgh, 0, 0, $bgcol);
imageCopyResampled($imgh, $timg, $posX, $posY, 0, 0, $newX, $newY, $image[0], $image[1]);
imageStringUp($imgh, $font, $maxX-9, $maxY-3, $copyright, $fgcol);
switch($image[2]) {
&& && case 1:
&&& header("Content-type: image/gif");
&& & && imageGIF($imgh);
&&& case 2:
&&& header("Content-type: image/jpeg");
&& & && imageJPEG($imgh);
&&& case 3:
&&& header("Content-type: image/png");
&& & && imagePNG($imgh);
imageDestroy($timg);
imageDestroy($imgh);
PHP imagepng note #28
"Tip: As with anything that outputs its result directly to the browser, you can use the output-control functions () to capture the output of this function, and save it in a string (for example)."
ob_start();
imagepng($image);
$image_data = ob_get_contents();
ob_end_clean();
And now you can save $image_data to a database, for example, instead of first writing it to file and then reading the data from it. Just don't forget to use mysql_escape_string...
PHP imagepng note #29
PNG files are already compressed. They use a lossless compression algorithm. If you are using HighColour images, the compression only does so much. For low colour images (16 or 256) the compression is much better.
It is pointless trying to compress the images further before sending to a browser.
PHP imagepng note #30
I have experienced segfaults and bus errors with the following configuration: FreeBSD4.4, Apache 1.3.26, PHP 4.2.2, GD-1.8.4, PDFlib 4.0.1. The apache process crashed when calling the imagepng function, but it didn't crash when calling the imagejpg function, or imagecreatefrompng...
&Some wasted hours (lots) later, in which I have tried to recompile gd, libpng, php, libjpeg, what-not, I have found the following advices:
&So the problem was not with the png library, but rather with the PDFlib. Even though all the threads led to a png-problem... so I have simply upgraded to PDFlib 4.0.3 (w/o any special --with-libpng didn't work anyways), recompiled PHP, and now everything works (imagepng, pdf creation, etc.).
&Hope this helps,
PHP imagepng note #31
Better than a chmod 777 to any '/dir/pic.png' you should :
- test if dir is writable (is_writable func.)
- use chmod 700 (more secure because let only the webserver ID have access)
In any case you should program a (crontab) script to change the owner ID of any images created.
PHPGD - 函数}

我要回帖

更多关于 php 生成图片效率 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信