php美元符号怎么打,php – 在前面调用带有美元符号的函数

标签:php

我是php的新手,我找到了一个关于裁剪图像的教程,我从未看到过一个奇怪的指令.我不知道如何搜索它.

$src_img = $image_create($source_file);

这是本教程的完整代码

//resize and crop image by center

function resize_crop_image($max_width, $max_height, $source_file, $dst_dir, $quality = 80){

$imgsize = getimagesize($source_file);

$width = $imgsize[0];

$height = $imgsize[1];

$mime = $imgsize['mime'];

switch($mime){

case 'image/gif':

$image_create = "imagecreatefromgif";

$image = "imagegif";

break;

case 'image/png':

$image_create = "imagecreatefrompng";

$image = "imagepng";

$quality = 7;

break;

case 'image/jpeg':

$image_create = "imagecreatefromjpeg";

$image = "imagejpeg";

$quality = 80;

break;

default:

return false;

break;

}

$dst_img = imagecreatetruecolor($max_width, $max_height);

$src_img = $image_create($source_file);

$width_new = $height * $max_width / $max_height;

$height_new = $width * $max_height / $max_width;

//if the new width is greater than the actual width of the image, then the height is too large and the rest cut off, or vice versa

if($width_new > $width){

//cut point by height

$h_point = (($height - $height_new) / 2);

//copy image

imagecopyresampled($dst_img, $src_img, 0, 0, 0, $h_point, $max_width, $max_height, $width, $height_new);

}else{

//cut point by width

$w_point = (($width - $width_new) / 2);

imagecopyresampled($dst_img, $src_img, 0, 0, $w_point, 0, $max_width, $max_height, $width_new, $height);

}

$image($dst_img, $dst_dir, $quality);

if($dst_img)imagedestroy($dst_img);

if($src_img)imagedestroy($src_img);

}

//usage example

resize_crop_image(100, 100, "test.jpg", "test.jpg");

解决方法:

$image_create返回一个字符串.

这个刺痛是一个动态函数(其名称取决于运行时间)

参考:

而不是添加3个if语句来选择三个函数:

imagecreatefromgif(),imagecreatefrompng()和imagecreatefromjpeg(),

获取一个变量,它将切换函数变量(名称)并将使用该变量.

哪个更容易使用.

标签:php

来源: https://codeday.me/bug/20190715/1466224.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值