调整图像大小并命名
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了调整图像大小并命名相关的知识,希望对你有一定的参考价值。
This properly handles transparencies for PNG/GIF.
/** * Resizes and renames an image file * @return resource An image identifier * @return false on error * @param string $source Path to source image * @param string $dest Path to output image * @param int $n_height New height to set image to * @param int $n_width New width to set image to * @param bool $overwrite Allow overwrite of image file * @author Glen Solsberry <[email protected]> */ function resize_and_name_image($source, $dest, $n_height, $n_width, $overwrite = false) { if (file_exists($dest) && !$overwrite) { error_log("$dest exists, and we're not overwriting"); return false; } if ($width > $height) { $n_height = ($n_width / $width) * $height; } else { $n_width = ($n_height / $height) * $width; } // call the appropriate imagecreatefrom function for this image } else { display_error("invalid_image_format"); return false; } // imagecolorallocatealpha($new_img, 0, 0, 0, 0); // get and reallocate transparency-color if ($transindex >= 0) { $transindex = imagecolorallocatealpha($new_img, $transcol['red'], $transcol['green'], $transcol['blue'], 127); } else if ($transindex == -1) { } // stuff the existing file off in to a backup directory // we need to get the end path // make sure that the directory exists } } // write the image out to the new file, using imagepng/imagegif/etc return $res; } else { return false; } }
以上是关于调整图像大小并命名的主要内容,如果未能解决你的问题,请参考以下文章