Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在用户端之前调整图像大小_Php - Fatal编程技术网

Php 在用户端之前调整图像大小

Php 在用户端之前调整图像大小,php,Php,更新: 现在我学到了更多,我看了很多,修改了我得到了这个: function show_image($image, $new_width, $new_height) { //$this->helper('file'); why need this? //$image_content = read_file($image); We does not want to use this as output. list($old

更新: 现在我学到了更多,我看了很多,修改了我得到了这个:

function show_image($image, $new_width, $new_height) {
    //$this->helper('file');                   why need this?
    //$image_content = read_file($image);      We does not want to use this as output.
    list($old_width,$old_height) = getimagesize("$image");
    //resize image
    $image = imagecreatefromjpeg($image);
    $thumbImage = imagecreatetruecolor($new_width, $new_height);
    imagecopyresized($thumbImage, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
    imagedestroy($image);
    //imagedestroy($thumbImage); do not destroy before display :)
    ob_end_clean();  // clean the output buffer ... if turned on.
    header('Content-Type: image/jpeg');
    imagejpeg($thumbImage); //you does not want to save.. just display
    imagedestroy($thumbImage); //but not needed, cause the script exit in next line and free the used memory
    exit;
} 当使用这个函数时,我得到一个文件,但我需要得到一个URL 我希望能够使用:

 <img src=" ... ">

由于您不能在服务器上使用GD,一个好的选择可能是在客户端处理它

我想到的一个想法是将图像加载到html5画布中,并在将其上传到服务器之前使用该画布操纵图像特征

这篇文章讨论了如何直接从画布上传图像数据,并将其保存为服务器上的图像

您可能还需要查看JavaScript文件API,以便将图像加载到客户端的画布中


这不一定是一个简单的解决方案,但如果不访问GD和其他内容,它可能是您的最佳拍摄方式。

我假设这些是用户上传的图像?你想要一个小的和全分辨率的版本吗?是的,没错,我想展示300*150的图片。你在谷歌试试吗@MiChAeLoKGB我相信您发布的链接中包含的图像操纵器库依赖于GD,这在相关服务器上不可用。@Harvtronix如果他不能使用GD、Imagick或Gmagick,那么他就完蛋了。您可以使用jQuery等进行客户端裁剪,但用于将它们保存在服务器上?没有这些,这是有问题的。如果他可以使用其中一个,那么我是一个新手,我刚刚发现在服务器中启用了GD,我该如何使用GD呢?