doucan8276 2014-02-02 14:21
浏览 32
已采纳

旋转的图像不会在PHP中显示

So i am trying to create a compass to show wind direction.

 Function rotate($angle) {
     $original = imagecreatefrompng("img/Arrow.png");
     $compass = imagerotate($original, $angle, 0);
     return $compass;
 }

That will be displayed using some html that i am echoing. The variable angle is being passed from a database. The html on the php script looks like this:

<img src='".rotate($row['wind_dir'])."'/>

The image never displays, and clearly the browser does not know where it is.

When i view the html in my browser, the above line shows as

<img src="Resource id #4"/>

and when i click on it, it navigates to a 404.

What am i doing wrong? Have i forgotten a line in the image rotation function?

EDIT: Having tried some of the responses below, i get an image, but it only shows as a black box!

EDIT2:

Well after much fiddling, it turns out all that was needed was to the third value of imagerotate() to -1 as follows:

$original = imagecreatefrompng("img/goog.png");
$compass = imagerotate($original, $angle, -1);
imagealphablending($compass, true);
imagesavealpha($compass, true);
header('Content-Type: image/png');
imagepng($compass);
imagedestroy($compass);
  • 写回答

3条回答 默认 最新

  • doutuo7609 2014-02-02 14:33
    关注

    You have to execute the function and send header: try like below, say our php file name is rotate.php :

    rotate.php

    function rotate($angle) {
         $original = imagecreatefrompng("test.png");
         $compass = imagerotate($original, $angle, 0);
         header('Content-Type: image/png');
         imagepng($compass);
         imagedestroy($compass);
     }
    
    if(isset($_GET['angle'])){
     rotate($_GET['angle']);
    }
    

    THen in your html you can call the web resource i.e you php file as:

    <img src="url_to_rotate.php?angle=90" />
    

    Also remember to sanitize the GET input before executing it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测