doutou3725 2017-07-08 16:06
浏览 22

调整图像功能实现页面大小

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);
?>

Above is code which i use to resize any image (e.g http://example.com/resize.php?w=480&h=320&q=50&img=http://example.com/image.jpg)

But i'm resizing images on just single page in my website so i wanted to implement the code inside that page as a function and put the result of that function in an <img> tag.

  • 写回答

1条回答 默认 最新

  • douyou7102 2017-07-08 16:10
    关注

    You can use a data-url for that:

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

    Your resizeImg() would then need to echo out the image base64 encoded like this:

    echo base64_encode(...);
    
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法