在线涂改图片 php,php网站怎么修改图片[通俗易懂]

在线涂改图片 php,php网站怎么修改图片[通俗易懂]主要还是用到php中的GD库中的函数upload_image.php,主要是一个上传控件,用来选择图片YourusernameUploadimage**Acceptableimageformatsinclude:GIF,JPG/JPEGandPNG.ImageCaption然后是上传和处理图片的逻辑check_image.php…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

9ef942c5d9d8e919d58dd6bdd6ad6141.png

主要还是用到php中的GD库中的函数

upload_image.php,主要是一个上传控件,用来选择图片

Your username
Upload image*

* Acceptable image formats include: GIF, JPG/JPEG and PNG.

Image Caption

然后是上传和处理图片的逻辑check_image.php<?php

//修改图片效果

$db = mysql_connect(‘localhost’,’root’,’Ctrip07185419′) or die(‘can not connect to database’);

mysql_select_db(‘moviesite’,$db) or die(mysql_error($db));

//上传文件的路径

$dir = ‘D:\Serious\phpdev\test\images’;

//upload_image.php页面传递过来的参数,如果是上传图片

if($_POST[‘submit’] == ‘Upload’)

{

if($_FILES[‘uploadfile’][‘error’] != UPLOAD_ERR_OK)

{

switch($_FILES[‘uploadfiel’][‘error’])

{

case UPLOAD_ERR_INI_SIZE:

die(‘The uploaded file exceeds the upload_max_filesize directive’);

break;

case UPLOAD_ERR_FORM_SIZE:

die(‘The upload file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form’);

break;

case UPLOAD_ERR_PARTIAL:

die(‘The uploaded file was only partially uploaded’);

break;

case UPLOAD_ERR_NO_FILE:

die(‘No file was uploaded’);

break;

case UPLOAD_ERR_NO_TMP_DIR:

die(‘The server is missing a temporary folder’);

break;

case UPLOAD_ERR_CANT_WRITE:

die(‘The server fail to write the uploaded file to the disk’);

break;

case UPLOAD_ERR_EXTENSION:

die(‘The upload stopped by extension’);

break;

}

}

$image_caption = $_POST[‘caption’];

$image_username = $_POST[‘username’];

$image_date = date(‘Y-m-d’);

list($width,$height,$type,$attr) = getimagesize($_FILES[‘uploadfile’][‘tmp_name’]);

$error = ‘The file you upload is not a supported filetype’;

switch($type)

{

case IMAGETYPE_GIF:

$image = imagecreatefromgif($_FILES[‘uploadfile’][‘tmp_name’]) or die($error);

break;

case IMAGETYPE_JPEG:

$image = imagecreatefromjpeg($_FILES[‘uploadfile’][‘tmp_name’]) or die($error);

break;

case IMAGETYPE_PNG:

$image = imagecreatefrompng($_FILES[‘uploadfile’][‘tmp_name’]) or die($error);

break;

default:

break;

}

$query = ‘insert into images(image_caption,image_username,image_date) values(“‘.$image_caption.'” , “‘.$image_username.'”,”‘.$image_date.'”)’;

$result = mysql_query($query,$db) or die(mysql_error($db));

$last_id = mysql_insert_id();

// $imagename = $last_id.’.jpg’;

// imagejpeg($image,$dir.’/’.$imagename);

// imagedestroy($image);

$image_id = $last_id;

imagejpeg($image , $dir.’/’.$image_id.’.jpg’);

imagedestroy($image);

}

else //如果图片已经上传,则从数据库中取图片名字

{

$query = ‘select image_id,image_caption,image_username,image_date from images where image_id=’.$_POST[‘id’];

$result = mysql_query($query,$db) or die(mysql_error($db));

extract(mysql_fetch_assoc($result));

list($width,$height,$type,$attr) = getimagesize($dir.’/’.$image_id.’.jpg’);

}

//如果是保存图片

if($_POST[‘submit’] == ‘Save’)

{

if(isset($_POST[‘id’]) && ctype_digit($_POST[‘id’]) && file_exists($dir.’/’.$_POST[‘id’].’.jpg’))

{

$image = imagecreatefromjpeg($dir.’/’.$_POST[‘id’].’.jpg’);

}

else

{

die(‘invalid image specified’);

}

$effect = (isset($_POST[‘effect’])) ? $_POST[‘effect’] : -1;

switch($effect)

{

case IMG_FILTER_NEGATE:

imagefilter($image , IMG_FILTER_NEGATE); //将图像中所有颜色反转

break;

case IMG_FILTER_GRAYSCALE:

imagefilter($image , IMG_FILTER_GRAYSCALE); //将图像转换为灰度的

break;

case IMG_FILTER_EMBOSS:

imagefilter($image , IMG_FILTER_EMBOSS); //使图像浮雕化

break;

case IMG_FILTER_GAUSSIAN_BLUR:

imagefilter($image , IMG_FILTER_GAUSSIAN_BLUR); //用高斯算法模糊图像

break;

}

imagejpeg($image , $dir.’/’.$_POST[‘id’].’.jpg’ , 100);

?>

Here is your pic!

Your image has been saved!

在线涂改图片 php,php网站怎么修改图片[通俗易懂]

}

else

{

?>

Here is your pic!

So how does it feel to be famous?

Here is the picture you just uploaded to your servers:

if($_POST[‘submit’] == ‘Upload’)

{

$imagename = ‘images/’.$image_id.’.jpg’;

}

else

{

$imagename = ‘image_effect.php?id=’.$image_id.’&e=’.$_POST[‘effect’];

}

?>

在线涂改图片 php,php网站怎么修改图片[通俗易懂]

Image save as: <?php $image_id?>
Height: <?php echo $height;?>
Widht: <?php echo $width;?>
Upload date: <?php echo $image_date;?>

You may apply a special effect to your image from the list of option below.

Note:saving an image with any of the filters applied can be undone

None

echo ‘

if(isset($_POST[‘effect’]) && $_POST[‘effect’] == IMG_FILTER_GRAYSCALE)

{

echo ‘selected=”selected”‘;

}

echo ‘ >Black and white

‘;

echo ‘

if(isset($_POST[‘effect’]) && $_POST[‘effect’] == IMG_FILTER_GAUSSIAN_BLUR)

{

echo ‘ selected=”selected”‘;

}

echo ‘>Blur

‘;

echo ‘

if(isset($_POST[‘effect’]) && $_POST[‘effect’] == IMG_FILTER_EMBOSS)

{

echo ‘selected=”selected”‘;

}

echo ‘>Emboss

‘;

echo ‘

if(isset($_POST[‘effect’]) && $_POST[‘effect’] == IMG_FILTER_NEGATE)

{

echo ‘selected=”selected”‘;

}

echo ‘>Negative

‘;

?>

}

?>

最后是一个预览效果的页面image_effect.php<?php

$dir = ‘D:\Serious\phpdev\test\images’;

if(isset($_GET[‘id’]) && ctype_digit($_GET[‘id’]) && file_exists($dir.’/’.$_GET[‘id’].’.jpg’))

{

$image = imagecreatefromjpeg($dir.’/’.$_GET[‘id’].’.jpg’);

}

else

{

die(‘invalid image specified’);

}

$effect = (isset($_GET[‘e’])) ? $_GET[‘e’] : -1;

switch($effect)

{

case IMG_FILTER_NEGATE:

imagefilter($image , IMG_FILTER_NEGATE);

break;

case IMG_FILTER_GRAYSCALE:

imagefilter($image , IMG_FILTER_GRAYSCALE);

break;

case IMG_FILTER_EMBOSS:

imagefilter($image , IMG_FILTER_EMBOSS);

break;

case IMG_FILTER_GAUSSIAN_BLUR:

imagefilter($image , IMG_FILTER_GAUSSIAN_BLUR);

break;

}

header(‘Content-Type:image/jpeg’);

imagejpeg($image , ” , 100);

?>

当使用imagefilter方法处理图片之后会把图片输出到页面,这里要注意imagejpeg方法的第二个参数是空字符串,这样它就不会写入到硬盘中了,如果第二个参数设置了会覆盖原有的图片,这样可以让用户在保存图片之前随意的预览效果,如下:header(‘Content-Type:image/jpeg’);

imagejpeg($image , ” , 100);

在check_image.php中有调用到类似的方法,但是这里指定了第二个参数,就是用来保存图片的:imagejpeg($image , $dir.’/’.$_POST[‘id’].’.jpg’ , 100);

php中处理图片的方法:

IMG_FILTER_NEGATE:将图像中所有颜色反转。

IMG_FILTER_GRAYSCALE:将图像转换为灰度的。

IMG_FILTER_BRIGHTNESS:改变图像的亮度。用 arg1 设定亮度级别。

IMG_FILTER_CONTRAST:改变图像的对比度。用 arg1 设定对比度级别。

IMG_FILTER_COLORIZE:与 IMG_FILTER_GRAYSCALE 类似,不过可以指定颜色。用 arg1,arg2 和 arg3 分别指定 red,blue 和 green。每种颜色范围是 0 到 255。

IMG_FILTER_EDGEDETECT:用边缘检测来突出图像的边缘。

IMG_FILTER_EMBOSS:使图像浮雕化。

IMG_FILTER_GAUSSIAN_BLUR:用高斯算法模糊图像。

IMG_FILTER_SELECTIVE_BLUR:模糊图像。

IMG_FILTER_MEAN_REMOVAL:用平均移除法来达到轮廓效果。

IMG_FILTER_SMOOTH:使图像更柔滑。用 arg1 设定柔滑级别。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/196358.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 网站模板 收集[通俗易懂]

    网站模板 收集[通俗易懂]http://www.wzjs.info/bz.asp?classid=130http://www.wzjs.info/网站超市https://www.kuicms.com/魅网https://templets.kui.net/k0001/https://templets.kui.net/k0205/魅网内页(可直接扣)https://www.sitestar.cn/website/combination_templates.aspx?type=all建站之星(可扣)h…

    2022年7月24日
    8
  • AE 先进的视频画面 快速释放 慢动作

    AE 先进的视频画面 快速释放 慢动作

    2022年1月7日
    117
  • 自监督学习 对比学习了解

    自监督学习 对比学习了解简介自监督学习是近几年(2020年)流行起来的一种机器学习方法,很多人认为自监督方法未来一段时间将取代现有的监督方法,成为深度学习中占据主导地位的方法。现在已经有不少采用自监督-对比学习的方法取得了领先的效果。目前(2020.10)来说这个领域貌似还比较新,没有找到很系统的讲解介绍资料。首先介绍一下到底什么是SSL,我们知道一般机器学习分为监督学习,非监督学习和强化学习。而self-supervisedlearning是无监督学习里面的一种。自监督学习的思想非常简单,就是输入的是一堆无监督的数据

    2025年11月15日
    3
  • stagefright概述「建议收藏」

    stagefright概述「建议收藏」一、android结构图(上下文关系)   二、android目录结构 自从android4.2版本之后,媒体的相关代码都放到framework/av/的目录中,俗称”AV工作者”,呵呵(本地代码不是太健全,目录我手动敲,公司代码健全,直接导出目录树)  [plain]viewplaincopyprint?|—– m

    2025年8月9日
    3
  • 大数据科研解决方案「建议收藏」

    大数据科研解决方案「建议收藏」第一章建设背景1.1国家政策2017年1月工业和信息化部正式发布了《大数据产业发展规划(2016-2020年)》,明确了“十三五”时期大数据产业的发展思路、原则和目标,将引导大数据产业持续健康发展,有力支撑制造强国和网络强国建设。2018年9月工信部公示“2018年大数据产业发展试点示范项目名单”,公布了包括大数据存储管理、大数据分析挖掘、大数据安全保障、产业创新大数据应用、…

    2022年5月30日
    54
  • 常见分布式id生成方案_分布式id生成方案

    常见分布式id生成方案_分布式id生成方案文章目录一、为什么要用分布式ID1、什么是分布式ID2、那么分布式ID需要满足哪些条件二、分布式ID有哪些生成方式1、基于UUID2、基于数据库自增ID3、基于数据库集群模式4、基于数据库的号段模式5、基于Redis模式6、基于雪花算法(Snowflake)模式7、百度(uid-generator)8、美团(Leaf)号段模式snowflake模式9、滴滴(Tinyid)Http方式接入Java客户端方式接入三、总结一、为什么要用分布式ID在说分布式ID的具体实现之前,我们来简单分析一下为什么用分布式

    2025年7月28日
    7

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号