du2229 2011-04-23 21:19
浏览 54

在没有修改原始图像的情况下在图像上添加边框

I would like to add bottom border of 10px height on bottom of every image WITHOUT resizing the original image.

Exemple: i have one jpg 300X200 px, i add black border of 10 px height on the bottom, my image is now 300X210 with black border.

Thanks for your help

  • 写回答

2条回答 默认 最新

  • duanbicheng3345 2011-04-24 05:52
    关注

    Here is a code sample that will draw a border. I have used the GET variable to call the image.

    If you for example put this code in your images folder, you can call example.org/images/resize.php?path=image.jpg, without modifying the original image. You can even use mod_rewrite (assuming you are using apache) to apply this filter.

    However, this may affect the performance (doing it on the fly), so I recommend at least caching the images on the server, or just saving them to disk.

    <?php 
    
    $img = ImageCreateFromJPEG($_GET['path']); 
    
    // Draw border 
    $color_black = ImageColorAllocate($img, 0, 0, 0); 
    drawBorder($img, $color_black, 10); 
    
    
    // Output 
    header('Content-type: image/jpeg'); 
    ImageJPEG($img); 
    
    
    
    // Draw a border 
    function drawBorder(&$img, &$color, $thickness) 
    {  
        $x = ImageSX($img); 
        $y = ImageSY($img); 
    
        for($i = 0; $i < $thickness; $i++) 
            ImageRectangle($img, 0, 0, $x, $y--, $color_black); 
    } 
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线