本文整理汇总了PHP中ImageCreateFromPNG函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageCreateFromPNG函数的具体用法?PHP ImageCreateFromPNG怎么用?PHP ImageCreateFromPNG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageCreateFromPNG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: thumbnail
function thumbnail($PicPathIn, $PicPathOut, $PicFilenameIn, $PicFilenameOut, $neueHoehe, $Quality)
{
// Bilddaten ermitteln
$size = getimagesize("{$PicPathIn}" . "{$PicFilenameIn}");
$breite = $size[0];
$hoehe = $size[1];
$neueBreite = intval($breite * $neueHoehe / $hoehe);
if ($size[2] == 1) {
// GIF
$altesBild = ImageCreateFromGIF("{$PicPathIn}" . "{$PicFilenameIn}");
$neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
imageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
}
if ($size[2] == 2) {
// JPG
$altesBild = ImageCreateFromJPEG("{$PicPathIn}" . "{$PicFilenameIn}");
$neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
}
if ($size[2] == 3) {
// PNG
$altesBild = ImageCreateFromPNG("{$PicPathIn}" . "{$PicFilenameIn}");
$neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
}
}
示例2: open_image
function open_image($file = null)
{
$image_type = $this->image_type($file);
if (!$image_type) {
trigger_error("Invalid image file: {$file}.", E_USER_ERROR);
}
$this->type = $image_type[0];
$this->width = $image_type[1];
$this->height = $image_type[2];
if (!in_array($this->type, $this->supported_img_types)) {
trigger_error("File type '{$this->type}' not supported.", E_USER_ERROR);
}
// Destroy if already open
if ($this->image) {
ImageDestroy($this->image);
}
switch ($this->type) {
case 'JPG':
$this->image = ImageCreateFromJPEG($file);
break;
case 'GIF':
$this->image = ImageCreateFromGIF($file);
break;
case 'PNG':
$this->image = ImageCreateFromPNG($file);
break;
}
}
示例3: thumbnail
function thumbnail($imgfile)
{
//detect image format
//$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
$this->img["format"] = preg_replace('/.*\\.(.*)$/', "\\1", $imgfile);
$this->img["format"] = strtoupper($this->img["format"]);
if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
//JPEG
$this->img["format"] = "JPEG";
$this->img["src"] = ImageCreateFromJPEG($imgfile);
} elseif ($this->img["format"] == "PNG") {
//PNG
$this->img["format"] = "PNG";
$this->img["src"] = ImageCreateFromPNG($imgfile);
} elseif ($this->img["format"] == "GIF") {
//GIF
$this->img["format"] = "GIF";
$this->img["src"] = ImageCreateFromGIF($imgfile);
} elseif ($this->img["format"] == "WBMP") {
//WBMP
$this->img["format"] = "WBMP";
$this->img["src"] = ImageCreateFromWBMP($imgfile);
} else {
//DEFAULT
echo "Not Supported File";
exit;
}
@($this->img["lebar"] = imagesx($this->img["src"]));
@($this->img["tinggi"] = imagesy($this->img["src"]));
//default quality jpeg
$this->img["quality"] = 75;
}
示例4: src
public function src($src, $ext = null)
{
if (!is_file($src)) {
throw new FileNotFoundException($src);
}
$this->src = $src;
if (!$ext) {
$info = new \SplFileInfo($src);
$this->ext = strtoupper($info->getExtension());
} else {
$this->ext = strtoupper($ext);
}
if (is_file($src) && ($this->ext == "JPG" or $this->ext == "JPEG")) {
$this->image = ImageCreateFromJPEG($src);
} else {
if (is_file($src) && $this->ext == "PNG") {
$this->image = ImageCreateFromPNG($src);
} else {
throw new FileNotFoundException($src);
}
}
$this->input_width = imagesx($this->image);
$this->input_height = imagesy($this->image);
return $this;
}
示例5: getColorForCaptchaReturnInt
/**
* getColorForCaptcha Test
*
* @param string $hexColorString
* @param string $expectedResult
* @dataProvider getColorForCaptchaReturnIntDataProvider
* @return void
* @test
*/
public function getColorForCaptchaReturnInt($hexColorString, $expectedResult)
{
$imageResource = ImageCreateFromPNG(GeneralUtility::getFileAbsFileName('typo3conf/ext/powermail/Resources/Private/Image/captcha_bg.png'));
$this->generalValidatorMock->_set('configuration', array('captcha.' => array('default.' => array('textColor' => $hexColorString))));
$result = $this->generalValidatorMock->_call('getColorForCaptcha', $imageResource);
$this->assertSame($expectedResult, $result);
}
示例6: TransFormPicture
function TransFormPicture($inputfname, $outputfname, $transform, $backgroundcolor)
{
$img_in = ImageCreateFromPNG($inputfname);
$sizex = imagesx($img_in);
$sizey = imagesy($img_in);
$img_out = @ImageCreateTrueColor($sizex, $sizey) or die("Cannot create image handle.");
imagefill($img_out, 0, 0, hexdec($backgroundcolor));
ImageCopy($img_out, $img_in, 0, 0, 0, 0, $sizex, $sizey);
for ($x = 0; $x < $sizex; $x++) {
for ($y = 0; $y < $sizey; $y++) {
$color = imagecolorat($img_in, $x, $y);
$allcolors[dechex($color)]++;
$blue = 0xff & $color;
$green = (0xff00 & $color) >> 8;
$red = (0xff0000 & $color) >> 16;
foreach ($transform as $line) {
list($from, $to) = split("\t", $line);
list($fr, $fg, $fb) = sscanf($from, '%2x%2x%2x');
if ($blue == $fb and $red == $fr and $green == $fg) {
imagesetpixel($img_out, $x, $y, hexdec($to));
}
}
}
}
ImagePNG($img_out, "out/{$outputfname}");
imagedestroy($img_in);
imagedestroy($img_out);
print_r($allcolors);
}
示例7: marcadeagua
function marcadeagua($img_original, $img_marcadeagua, $img_nueva, $calidad)
{
// obtener datos de la fotografia
$info_original = getimagesize($img_original);
$anchura_original = $info_original[0];
$altura_original = $info_original[1];
// obtener datos de la "marca de agua"
$info_marcadeagua = getimagesize($img_marcadeagua);
$anchura_marcadeagua = $info_marcadeagua[0];
$altura_marcadeagua = $info_marcadeagua[1];
// calcular la posición donde debe copiarse la "marca de agua" en la fotografia
/*
// Posicion: Centrado
$horizmargen = ($anchura_original - $anchura_marcadeagua)/2;
$vertmargen = ($altura_original - $altura_marcadeagua)/2;
*/
// Posicion: abajo a la izquierda
$horizmargen = 10;
$vertmargen = $altura_original - $altura_marcadeagua - 10;
// crear imagen desde el original
$original = ImageCreateFromJPEG($img_original);
ImageAlphaBlending($original, true);
// crear nueva imagen desde la marca de agua
$marcadeagua = ImageCreateFromPNG($img_marcadeagua);
// copiar la "marca de agua" en la fotografia
ImageCopy($original, $marcadeagua, $horizmargen, $vertmargen, 0, 0, $anchura_marcadeagua, $altura_marcadeagua);
// guardar la nueva imagen
ImageJPEG($original, $img_nueva, $calidad);
// cerrar las imágenes
ImageDestroy($original);
ImageDestroy($marcadeagua);
}
示例8: thumbnail
private function thumbnail($imgfile)
{
//detect image format
$this->acHWArr = getimagesize($imgfile);
$this->img["format"] = ereg_replace(".*\\.(.*)\$", "\\1", $imgfile);
$this->img["format"] = strtoupper($this->img["format"]);
if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
//JPEG
$this->img["format"] = "JPEG";
$this->img["src"] = ImageCreateFromJPEG($imgfile);
} elseif ($this->img["format"] == "PNG") {
//PNG
$this->img["format"] = "PNG";
$this->img["src"] = ImageCreateFromPNG($imgfile);
} elseif ($this->img["format"] == "GIF") {
//GIF
$this->img["format"] = "GIF";
$this->img["src"] = ImageCreateFromGIF($imgfile);
} elseif ($this->img["format"] == "WBMP") {
//WBMP
$this->img["format"] = "WBMP";
$this->img["src"] = ImageCreateFromWBMP($imgfile);
} else {
//DEFAULT
echo "Not Supported File <a href='" . $_SERVER[HTTP_REFERER] . "'>Back</a>";
exit;
}
@($this->img["lebar"] = imagesx($this->img["src"]));
@($this->img["tinggi"] = imagesy($this->img["src"]));
//default quality jpeg
$this->img["quality"] = 75;
}
示例9: _addWaterMark
/**
* Agrega una marca de agua a la foto
* @param string $absolutePath
*/
private function _addWaterMark($absolutePath)
{
$DOC_ROOT = $this->_CI->input->server('DOCUMENT_ROOT') . "/";
if (FALSE === is_file($absolutePath)) {
return FALSE;
}
switch (TRUE) {
case stristr($absolutePath, 'jpg'):
$photoImage = ImageCreateFromJpeg("{$absolutePath}");
break;
case stristr($absolutePath, 'gif'):
$photoImage = ImageCreateFromGIF("{$absolutePath}");
break;
case stristr($absolutePath, 'png'):
$photoImage = ImageCreateFromPNG("{$absolutePath}");
break;
}
ImageAlphaBlending($photoImage, true);
// Añadimos aquà el fichero de marca de agua.
$logoImage = ImageCreateFromPNG($DOC_ROOT . "assets/imagenes/marca_agua_telam.png");
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
$tamanox = imagesx($photoImage);
$ubicacionX = ($tamanox - $logoW) / 2;
$tamanoy = imagesy($photoImage);
$ubicacionY = ($tamanoy - $logoH) / 2;
ImageCopy($photoImage, $logoImage, $ubicacionX, $ubicacionY, 0, 0, $logoW, $logoH);
imagejpeg($photoImage, $absolutePath);
ImageDestroy($photoImage);
ImageDestroy($logoImage);
}
示例10: thumbnail
/**
* @private
*/
function thumbnail($imgfile)
{
//detect image format
$this->img["format"] = ereg_replace(".*\\.(.*)\$", "\\1", $imgfile);
$this->img["format"] = strtoupper($this->img["format"]);
if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
$this->img["format"] = "JPEG";
$this->img["src"] = @ImageCreateFromJPEG($imgfile);
} elseif ($this->img["format"] == "PNG") {
$this->img["format"] = "PNG";
$this->img["src"] = @ImageCreateFromPNG($imgfile);
} elseif ($this->img["format"] == "GIF") {
$this->img["format"] = "GIF";
if (function_exists("imagecreatefromgif")) {
$this->img["src"] = @ImageCreateFromGIF($imgfile);
} else {
return false;
}
} else {
// not a recognized format
throw new Exception("Trying to generate a thumbnail of an unsupported format!");
//die();
}
// check for errors
if (!$this->img["src"]) {
return false;
}
// if no errors, continue
@($this->img["lebar"] = imagesx($this->img["src"]));
@($this->img["tinggi"] = imagesy($this->img["src"]));
//default quality jpeg
$this->img["quality"] = 85;
return true;
}
示例11: TransformPicture
function TransformPicture($inputfname, $outputfname, $transform)
{
$img = ImageCreateFromPNG($inputfname);
Imagesavealpha($img, true);
$sizex = imagesx($img);
$sizey = imagesy($img);
for ($x = 0; $x < $sizex; $x++) {
for ($y = 0; $y < $sizey; $y++) {
$color = imagecolorat($img, $x, $y);
$allcolors[dechex($color)]++;
$blue = 0xff & $color;
$green = (0xff00 & $color) >> 8;
$red = (0xff0000 & $color) >> 16;
foreach ($transform as $line) {
list($from, $to) = split("\t", $line);
list($fr, $fg, $fb) = sscanf($from, '%2x%2x%2x');
if ($blue == $fb and $red == $fr and $green == $fg) {
imagesetpixel($img, $x, $y, hexdec($to));
}
}
}
}
ImagePNG($img, "{$outputfname}");
imagedestroy($img);
print_r($allcolors);
}
示例12: SetVar
function SetVar($srcFile, $echoType)
{
$this->srcFile = $srcFile;
$this->echoType = $echoType;
$info = '';
$data = GetImageSize($this->srcFile, $info);
switch ($data[2]) {
case 1:
if (!function_exists('imagecreatefromgif')) {
exit;
}
$this->im = ImageCreateFromGIF($this->srcFile);
break;
case 2:
if (!function_exists('imagecreatefromjpeg')) {
exit;
}
$this->im = ImageCreateFromJpeg($this->srcFile);
break;
case 3:
$this->im = ImageCreateFromPNG($this->srcFile);
break;
}
$this->srcW = ImageSX($this->im);
$this->srcH = ImageSY($this->im);
}
示例13: SetVar
function SetVar($srcFile, $echoType)
{
if (!file_exists($srcFile)) {
echo '源图片文件不存在!';
exit;
}
$this->srcFile = $srcFile;
$this->echoType = $echoType;
$info = "";
$data = GetImageSize($this->srcFile, $info);
switch ($data[2]) {
case 1:
if (!function_exists("imagecreatefromgif")) {
echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
exit;
}
$this->im = ImageCreateFromGIF($this->srcFile);
break;
case 2:
if (!function_exists("imagecreatefromjpeg")) {
echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>";
exit;
}
$this->im = ImageCreateFromJpeg($this->srcFile);
break;
case 3:
$this->im = ImageCreateFromPNG($this->srcFile);
break;
}
$this->srcW = ImageSX($this->im);
$this->srcH = ImageSY($this->im);
}
示例14: openImage
private function openImage($file)
{
// *** Get extension
$extension = strtolower(strrchr($file, '.'));
//$extension = DataHandler::returnExtensionOfFile($file);
switch ($extension) {
case '.jpg':
case '.jpeg':
$img = @imagecreatefromjpeg($file);
break;
case '.gif':
$img = @imagecreatefromgif($file);
break;
case '.png':
$img = @ImageCreateFromPNG($file);
// //abaixo do php.net
// imagealphablending($img, false);
// imagesavealpha($img, true);
break;
default:
$img = false;
break;
}
return $img;
}
示例15: resize
public function resize($width, $height)
{
$type = exif_imagetype($this->image);
if ($type == 2) {
$images_orig = ImageCreateFromJPEG($this->image);
} elseif ($type == 3) {
$images_orig = ImageCreateFromPNG($this->image);
} elseif ($type == 1) {
$images_orig = ImageCreateFromGIF($this->image);
} else {
return false;
}
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
if ($type == 2) {
ImageJPEG($images_fin, $this->image);
} elseif ($type == 3) {
ImagePNG($images_fin, $this->image);
} elseif ($type == 1) {
ImageGIF($images_fin, $this->image);
}
ImageDestroy($images_orig);
ImageDestroy($images_fin);
return true;
}