Symfony / liip_imagine : 图像路径解析结果为 404

服务器配置


Symfony 4.4.2

Apache 2.4.29

PHP: 7.3

Hosting: AWS LightSail

我使用 liip_imagine 包来处理上传的图像并使用 asset(). 不幸的是,图像 URL 解析为 404,我不知道为什么。


这是相关的树枝模板:


<div class="col">

  <p>{{ 'Current image' | trans }}</p>

      {% if module.image != '' %}

           <img style="width: 180px;" src="{{ asset(module.image | imagine_filter('learningModuleImage')) }}" alt="">

       {% endif %}

</div>

我检查了这个:

  • 文件已正确上传到 /public/upload 文件夹中。

  • module.image 确实包含图像哈希名称和扩展名:da305b9a0fee3eb7bdc5bfc9b64e88ff.jpeg

  • 真实网址: /public/upload/da305b9a0fee3eb7bdc5bfc9b64e88ff.jpeg

  • 生成的网址:https://domain.tld/media/cache/learningModuleImage/da305b9a0fee3eb7bdc5bfc9b64e88ff.jpeg

  • 配置:

liip_imagine:

    loaders:

        default:

            filesystem:

                data_root:

                    - "%kernel.project_dir%/public/upload"

                    - "%kernel.project_dir%/public/assets/img"


    resolvers:

        default:

            web_path:

                web_root: "%kernel.project_dir%/public/upload"

                cache_prefix: media/cache


    filter_sets:

        cache: ~

        learningModuleImage:

            filters:

                downscale:

                    max: [512, 512]

        profile:

            filters:

                downscale:

                    max: [512, 512]


        # the name of the "filter set"

        thumb:

            # adjust the image quality to 75%

            # quality: 75


            # list of transformations to apply (the "filters")

            filters:

                # create a thumbnail: set size to 120x90 and use the "outbound" mode

                # to crop the image when the size ratio of the input differs

                thumbnail: { size: [128, 128], mode: outbound }

                # create a 2px black border: center the thumbnail on a black background

                # 4px larger to create a 2px border around the final image

                # background: { size: [124, 94], position: center, color: '#000000' }


桃花长相依
浏览 107回答 1
1回答

有只小跳蛙

我解决了!这是工作配置。谢谢@MaulikParmar 的提示!liip_imagine:&nbsp; &nbsp; loaders:&nbsp; &nbsp; &nbsp; &nbsp; default:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filesystem:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data_root:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - "%kernel.project_dir%/public/upload"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - "%kernel.project_dir%/public/assets/img"&nbsp; &nbsp; resolvers:&nbsp; &nbsp; &nbsp; &nbsp; default:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; web_path:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; web_root: "%kernel.project_dir%/public"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cache_prefix: media/cache&nbsp; &nbsp; filter_sets:&nbsp; &nbsp; &nbsp; &nbsp; cache: ~&nbsp; &nbsp; &nbsp; &nbsp; learningModuleImage:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cache: default&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filters:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; downscale:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; max: [512, 512]&nbsp; &nbsp; &nbsp; &nbsp; profile:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filters:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; downscale:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; max: [512, 512]&nbsp; &nbsp; &nbsp; &nbsp; # the name of the "filter set"&nbsp; &nbsp; &nbsp; &nbsp; thumb:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # adjust the image quality to 75%&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # quality: 75&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cache: default&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # list of transformations to apply (the "filters")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filters:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # create a thumbnail: set size to 120x90 and use the "outbound" mode&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # to crop the image when the size ratio of the input differs&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thumbnail: { size: [128, 128], mode: outbound }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # create a 2px black border: center the thumbnail on a black background&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # 4px larger to create a 2px border around the final image&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # background: { size: [124, 94], position: center, color: '#000000' }
打开App,查看更多内容
随时随地看视频慕课网APP