dszdiavv474681 2018-04-28 10:37 采纳率: 0%
浏览 40

如何从输入文本(在网站中)模糊图像

I have website that users can find solutions (for any task). So I want to put solution in website but blur some part of solution text. I made it with css blur, but in developer mode (inspect element, ctrl+shift+i) all blurred text is visible. Question: How can I hide blurred text in source code of the website?

p.s. all of solutions will be inserted in text (not image)

  • 写回答

1条回答 默认 最新

  • dpj997991 2018-04-28 13:28
    关注

    You can generate the image at server side with GD library imagettftext() function, then apply the blur effect with imagefilter()

    Once you generated the image, you can replace the texts in your HTML code with <img> tags referring to the generated image.

    Example (probably not working, just an on-the-fly-coded theory):

    $fontType  = 'Arial';
    $fontSize  = 16; // px
    $source    = 'The solutions is to use GD library with imagettftext and imagefilter!';
    $blurTexts = ['GD', 'imagettftext', 'imagefilter'];
    
    // generate the images
    foreach( $blurTexts as $text ){
        // using strrev() just to confuse the hash-table users :P
        $imageFile = strrev(sha1($text)) . '.jpg'; 
        // dont generate same image twice
        if (file_exists($imageFile)) {
            continue;
        }
        $bounds = imagettfbbox($fontSize, 0, $fontType, $text);
        $width = $bounds[2]; // lower right corner, X position
        $height = $bounds[3]; // lower right corner, Y position
        $image = imagecreatetruecolor($width, $height);
        $color = imagecolorallocate($image, 0, 0, 0); // black
        imagettftext($image, $fontSize, 0, 0, 0, $color, $fontType, $text);
        imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
    
        // save the image
        imagejpeg($image, './' . $imageFile);
    
        // replace the text parts with the image
        $source = str_replace($text, "<img src='{$imageFile}'>", $source);
    }
    
    echo '<h1>Solutions:</h1><p>' + $source + '</p>';
    

    If you need to blur out longer texts (not just a few important keyword) then you will have to make more calculations (line breaks, etc)

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值