很多站长朋友们都不太清楚php截切图片,今天小编就来给大家整理php截切图片,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php求助图片缩放裁切问题 2、 php怎样截取视频图 3、 php如何实现图片的裁剪 4、 php 裁切图片问题 求助 5、 如何使用PHP动态把JPEG图片切割成几块 6、 PHP可以实现截图功能吗? php求助图片缩放裁切问题这段代码可以通过自已选择来决定图片的大小!
效果图如下所示:希望对你有帮助!
其中
minSize: [48,48],
setSelect: [0,0,190,190],
是调整选取范围的大小,若你 调整为120和160就改为了
setSelect: [0,0,120,160],
就可以了!
<?php
error_reporting(7);
date_default_timezone_set("Asia/Shanghai");
header("Content-type:text/html; Charset=utf-8");
require_once("./image.class.php");
$images = new Images("file");
if ($_GET['act'] == 'cut'){
$image = "/data/upload/help/202303/02/ad7ffe963687c817362beb2b4764e277.jpg";
$res = $images->thumb($image,false,1);
if($res == false){
echo "裁剪失败";
}elseif(is_array($res)){
echo '<img src="'.$res['big'].'" style="margin:10px;">';
echo '<img src="'.$res['small'].'" style="margin:10px;">';
}elseif(is_string($res)){
echo '<img src="'.$res.'">';
}
}elseif(isset($_GET['act']) $_GET['act'] == "upload"){
$path = $images->move_uploaded();
$images->thumb($path,false,0); //文件比规定的尺寸大则生成缩略图,小则保持原样
if($path == false){
$images->get_errMsg();
}else{
echo "上传成功!<a href='".$path."' target='_blank'>查看</a>";
}
}else{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ";quot;;>
<html>
<head>
<meta name="Author" content="SeekEver">
<meta name="Keywords" content="">
<meta name="Description" content="">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<script src="./js/jquery.min.js" type="text/javascript"></script>
<script src="./js/jquery.Jcrop.js" type="text/javascript"></script>
<link rel="stylesheet" href="./css/jquery.Jcrop.css" type="text/css" />
<script type="text/javascript">
jQuery(function($){
// Create variables (in this scope) to hold the API and image size
var jcrop_api, boundx, boundy;
$('#target').Jcrop({
minSize: [48,48],
setSelect: [0,0,190,190],
onChange: updatePreview,
onSelect: updatePreview,
onSelect: updateCoords,
aspectRatio: 1
},
function(){
// Use the API to get the real image size
var bounds = this.getBounds();
boundx = bounds[0];
boundy = bounds[1];
// Store the API in the jcrop_api variable
jcrop_api = this;
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
function updatePreview(c){
if (parseInt(c.w) > 0)
{
var rx = 48 / c.w; //小头像预览Div的大小
var ry = 48 / c.h;
$('#preview').css({
width: Math.round(rx * boundx) + 'px',
height: Math.round(ry * boundy) + 'px',
marginLeft: '-' + Math.round(rx * c.x) + 'px',
marginTop: '-' + Math.round(ry * c.y) + 'px'
});
}
{
var rx = 199 / c.w; //大头像预览Div的大小
var ry = 199 / c.h;
$('#preview2').css({
width: Math.round(rx * boundx) + 'px',
height: Math.round(ry * boundy) + 'px',
marginLeft: '-' + Math.round(rx * c.x) + 'px',
marginTop: '-' + Math.round(ry * c.y) + 'px'
});
}
};
});
</script>
</head>
<body>
<form method="post" action="?act=upload" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="上传">
</form>
<div style="float:left;"><img id="target" src="/data/upload/help/202303/02/ad7ffe963687c817362beb2b4764e277.jpg" ></div>
<div style="width:48px;height:48px;margin:10px;overflow:hidden; float:left;"><img style="float:left;" id="preview" src="/data/upload/help/202303/02/ad7ffe963687c817362beb2b4764e277.jpg" ></div>
<div style="width:190px;height:195px;margin:10px;overflow:hidden; float:left;"><img style="float:left;" id="preview2" src="/data/upload/help/202303/02/ad7ffe963687c817362beb2b4764e277.jpg" ></div>
<form action="index.php?act=cut" method="post" onsubmit="return checkCoords();">
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="submit" value="裁剪" />
</form>
</body>
</html>
<?php
}
?>
php怎样截取视频图用ffmpeg直接读取网站的某个视频,然后截取其中的某帧作为该视频的缩略图;读取网站自身提供的视频缩略图。
获取图片路径:
function get_youku_thumb($url) {
$content = file_get_contents($url);
preg_match( '/id="s_msn2".*?screenshot=(.*?)".?target=/', $content, $matchs );
return $matchs[1];
}
echo get_youku_thumb('视频网址');
把过去的图片WordPress的缩略图,可以将获取缩略图的代码做成shortcode,直接在文章中调用。也可以通过custom_field方式记录视频地址,在主循环中调用该函数获得缩略图,借助timthumb.php等脚本生成缓存存放到本地,就不用每次都去读网页了。
php如何实现图片的裁剪php中裁剪图片主要使用gd库的imagecopyresampled方法
$src_path = '1.jpg';
//创建源图的实例
$src = imagecreatefromstring(file_get_contents($src_path));
//裁剪开区域左上角的点的坐标
$x = 100;
$y = 12;
//裁剪区域的宽和高
$width = 200;
$height = 200;
//最终保存成图片的宽和高,和源要等比例,否则会变形
$final_width = 100;
$final_height = round($final_width * $height / $width);
//将裁剪区域复制到新图片上,并根据源和目标的宽高进行缩放或者拉升
$new_image = imagecreatetruecolor($final_width, $final_height);
imagecopyresampled($new_image, $src, 0, 0, $x, $y, $final_width, $final_height, $width, $height);
//输出图片
header('Content-Type: image/jpeg');
imagejpeg($new_image);
imagedestroy($src);
imagedestroy($new_image);
php 裁切图片问题 求助PHP做图片裁切
PHP做图片裁剪的原理是通过前台定位出要裁剪图片的左上角位置,及右下角位置的做标,如果有放大和缩小的话还要给出放大和缩小的百分比,以及要对哪一个图片进行操作,这几个值传到后台,在用PHP去处理!
前端图片坐标点的得到可以自己用JS去实现,如果你的JS写的不是很熟也没有关系,可以下载一个jsCropperUI这一个包里面有很多的DEMO,可以实现前台的拖曳效果了!
前台会有一个AJAX向后台发送数据,一般格式为x1="+position[0]+"y1="+position[1]+"x2="+position[2]+"y2="+position[3]+"r="+position[4]+"id = imgid四个坐标,缩放值,要操作的ID
后PHP接收这个数据后,进行操作
$x1 = $_GET['x1'];
$y1 = $_GET['y1'];
$x2 = $_GET['x2'];
$y2 = $_GET['y2'];
$r = $_GET['r'];
if($x2<$x1||$y2<$y1){
return false;
}
$img="dog.jpg";
$im=imagecreatefromjpeg($img);
$percent = $r*0.01;
list($width, $height) = getimagesize($img);
$new_width = $width * $percent;
$new_height = $height * $percent;
$tempimg = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($tempimg, $im,0,0,0,0, $new_width,$new_height, $width, $height);
imagejpeg($tempimg,"dog_temp.jpg");
ImageDestroy ($im);
$ims=$tempimg;
$srcW=ImageSX($ims);
$srcH=ImageSY($ims);
$top_x = $x1;
$top_y = $y1;
$bottom_x = $x2;
$bottom_y = $y2;
$newimg = imagecreatetruecolor($bottom_x-$top_x,$bottom_y-$top_y);
imagecopyresampled($newimg, $ims,0,0,$top_x,$top_y, $srcW,$srcH, $srcW, $srcH);
imagejpeg($newimg,"dogs.jpg");
ImageDestroy ($ims);
echo 1;
成功后输出1让前台得到进行裁剪区域的刷新!这样就可以实现PHP裁剪图片的效果了!
如何使用PHP动态把JPEG图片切割成几块<?php
$maxW=100; //准备将图片裁减成的小图的宽
$maxH=100; //准备将图片裁减成的小图的高
$link= "D:/Apache24/htdocs/web/test.jpg";//图片路径,自己修改
$img = imagecreatefromjpeg($link);
list($width, $height, $type, $attr) = getimagesize($link);
$widthnum=ceil($width/$maxW);
$heightnum=ceil($height/$maxH);
$iOut = imagecreatetruecolor ($maxW,$maxH);
//bool imagecopy ( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h )
//将 src_im 图像中坐标从 src_x,src_y 开始,宽度为 src_w,高度为 src_h 的一部分拷贝到 dst_im 图像中坐标为 dst_x 和 dst_y 的位置上。
for ($i=0;$i < $heightnum;$i++) {
for ($j=0;$j < $widthnum;$j++) {
imagecopy($iOut,$img,0,0,($j*$maxW),($i*$maxH),$maxW,$maxH);//复制图片的一部分
imagejpeg($iOut,"D:/Apache24/htdocs/web/img/".$i."_".$j.".jpg"); //输出成0_0.jpg,0_1.jpg这样的格式
}
}
?>
已测试,可以使用。
PHP可以实现截图功能吗?绝对可以
截图,生成图都可以...
你参考一下PHP中的处理图象的函数,
但要先安装GD库..否则你的机子不能处理图片
关于php截切图片的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。