php获取本地图片直接输出浏览器,file_get_contents:
function aa()
{
$url = './img/99.png';
//file_get_contents($url,true); 可以读取远程图片,也可以读取本地图片
$img = file_get_contents($url, true);
//使用图片头输出浏览器
header("Content-Type: image/jpeg;text/html; charset=utf-8");
echo $img;
exit;
}
aa();
第二种:
$url = './img/99.png';
header('Content-Type: application/pdf'); // PDF文件
$fp = fopen($url, "rb"); //二进制方式打开文件
fpassthru($fp); // 输出至浏览器
exit;
如果是图片,就修改header头
header('Content-Type: text/html; charset=utf-8'); //网页编码
15 header('Content-Type: text/plain'); //纯文本格式
16 header('Content-Type: image/jpeg'); //JPG、JPEG
17 header('Content-Type: application/zip'); // ZIP文件
18 header('Content-Type: application/pdf'); // PDF文件
19 header('Content-Type: audio/mpeg'); // 音频文件
20 header('Content-type: text/css'); //css文件
21 header('Content-type: text/javascript'); //js文件
22 header('Content-type: application/json'); //json
23 header('Content-type: application/pdf'); //pdf
24 header('Content-type: text/xml'); //xml
25 header('Content-Type: application/x-shockw**e-flash'); //Flash动画
裁剪图片:
function resize_image($file, $w, $h, $crop=FALSE) {
list($width, $height) = getimagesize($file);
$r = $width / $height;
if ($crop) {
if ($width > $height) {
$width = ceil($width-($width*abs($r-$w/$h)));
} else {
$height = ceil($height-($height*abs($r-$w/$h)));
}
$newwidth = $w;
$newheight = $h;
} else {
if ($w/$h > $r) {
$newwidth = $h*$r;
$newheight = $h;
} else {
$newheight = $w/$r;
$newwidth = $w;
}
}
$src = imagecreatefrompng($file);
$dst = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
return $dst;
}
$image = resize_image('go.png', 756, 756);
//imagepng($image, './icon-128x128.png');
imagepng($image, './icon-256x256.png');
var_dump($image);
提示:
switch ($file_type) {
case 'jpg':
$src = imagecreatefromjpeg($file);
$dst = imagecreatetruecolor($newwidth, $newheight);
break;
case 'png':
$src = imagecreatefrompng($file);
$dst = imagecreatetruecolor($newwidth, $newheight);
break;
case 'gif':
$src = imagecreatefromgif($file);
$dst = imagecreatetruecolor($newwidth, $newheight);
break;
case 'jpeg':
$src = imagecreatefromjpeg($file);
$dst = imagecreatetruecolor($newwidth, $newheight);
}
注释:
$resized_image = imagecreatetruecolor($target_width, $target_height);
switch ( $asset->a_mime_type )
{
case 'image/jpeg':
imagecopyresampled($resized_image, $source, 0, 0, 0, 0, $target_width, $target_height, $asset->a_image_width, $asset->a_image_height);
$r = imagejpeg($resized_image,$file_name);
break;
case 'image/png':
imagealphablending($resized_image, FALSE);
imagesavealpha($resized_image, TRUE);
imagecopyresampled($resized_image, $source, 0, 0, 0, 0, $target_width, $target_height, $asset->a_image_width, $asset->a_image_height);
$r = @imagepng($resized_image,$file_name);
break;
case 'image/gif':
imagecopyresampled($resized_image, $source, 0, 0, 0, 0, $target_width, $target_height, $asset->a_image_width, $asset->a_image_height);
$background = imagecolorallocate($resized_image, 0, 0, 0);
imagecolortransparent($resized_image, $background);
$r = @imagegif($resized_image,$file_name);
break;
}
laravel 批量更新:
https://blog.csdn.net/qq_28673091/article/details/100534908
https://blog.csdn.net/xiayu204575/article/details/106409495?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param
https://blog.csdn.net/amazingdyd/article/details/68924623?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.channel_param
LARAVEL orm 和 curl 常用方法:
https://blog.csdn.net/Wild_sir/article/details/102626096?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3.channel_param
LARAVEL 上传图片
https://blog.csdn.net/huang2017/article/details/70227850?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param