温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用php怎么在服务器端调整图片的大小

发布时间:2021-01-22 15:17:42 阅读:203 作者:Leah 栏目:开发技术
亿速云爆款云服务器,独享5M带宽,BGP线路,安全稳定,0.96元/天! 查看详情>>

这篇文章给大家介绍使用php怎么在服务器端调整图片的大小,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

<?php
 function imageResizer($url$width$height{
  header('Content-type: image/jpeg');
  list($width_orig$height_orig) = getimagesize($url);
  $ratio_orig $width_orig/$height_orig;
  if ($width/$height $ratio_orig) {
   $width $height*$ratio_orig;
  } else {
   $height $width/$ratio_orig;
  }
  // This resamples the image
  $image_p imagecreatetruecolor($width$height);
  $image imagecreatefromjpeg($url);
  imagecopyresampled($image_p$image0000$width$height$width_orig$height_orig);
  // Output the image
  imagejpeg($image_pnull100);
 }
 //works with both POST and GET
 $method $_SERVER['REQUEST_METHOD'];
 if ($method == 'GET') {
  imageResize($_GET['url'], $_GET['w'], $_GET['h']);
  } elseif ($method == 'POST') {
  imageResize($_POST['url'], $_POST['w'], $_POST['h']);
  }
 // makes the process simpler
 function loadImage($url$width$height){
  echo 'image.php?url='urlencode($url) ,
  '&w=',$width,
  '&h=',$height;
 }
?>

用法:

//Above code would be in a file called image.php.
//Images would be displayed like this:
<img src="<?php loadImage('image.jpg'5050?>" alt="" />

关于使用php怎么在服务器端调整图片的大小就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×