Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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_Gd_Image Resizing - Fatal编程技术网

Php 在页面中调整图像函数大小的实现

Php 在页面中调整图像函数大小的实现,php,gd,image-resizing,Php,Gd,Image Resizing,resize.php <?php function resizeImg($new_width, $new_height, $get_image, $quality){ ini_set("allow_url_fopen", 1); list($old_width, $old_height) = getimagesize($get_image); $image_p = imagecreatetruecolor($new_width, $new_height);

resize.php

<?php
function resizeImg($new_width, $new_height, $get_image, $quality){
    ini_set("allow_url_fopen", 1);
    list($old_width, $old_height) = getimagesize($get_image);
    $image_p = imagecreatetruecolor($new_width, $new_height);
    $image = imagecreatefromjpeg($get_image);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
    header('Content-Type: image/jpeg');
    imagejpeg($image_p, NULL, $quality);
}
$new_width = $_GET['w'];
$new_height = $_GET['h'];
$get_image = $_GET['img'];
$get_quality = $_GET['q'];
if($get_quality == NULL){$quality = "80";}
else{$quality = $get_quality;}
resizeImg($new_width, $new_height, $get_image, $quality);
?>

上面是我用来调整任何图像大小的代码(例如)


但是我正在调整网站中单个页面上的图像大小,因此我想将该页面中的代码作为一个函数实现,并将该函数的结果放入一个标签中。

您可以使用数据url来实现:

<img src="data:image/jpeg;base64,<?php echo resizeImg(...) ?>"/>

谢谢你的回答,我试图实现它,但失败了,我不是这方面的专家。那么,你能告诉我如何准确地实施它吗
echo base64_encode(...);