cloudinary-vue icon indicating copy to clipboard operation
cloudinary-vue copied to clipboard

<cld-transformation :effect="effect" />生成的url中effect无效

Open emoyee opened this issue 2 years ago • 29 comments

代码:<cld-transformation :effect="effect" /> 生成结果:image这是生成错误的url 代码:<cld-transformation effect="art:athena" /> 生成结果:image这便是生成正确的url

emoyee avatar May 30 '22 02:05 emoyee

effect我打印出来过,值没有问题 全部逻辑代码:

changeStyle:function(e){
        let _this = this;
        switch (e) {
          case '素描':_this.effect="art:incognito";break;
          case '复古':_this.effect="sepia";break;
          case '模糊':_this.effect="pixelate:10";break;
          case '卡通化':_this.effect="cartoonify";break;
        }
        var cloudinary=document.getElementById("imgPic");
        console.log(_this.effect);
        console.log(cloudinary);
        _this.changePic(e);
      },
      changePic(style){
        let _this = this;
        _this.src=_this.srced;
        var c=document.getElementById("myCanvas1");
        var ctx=c.getContext("2d");
        var img=new Image();
        img.src=_this.srced;
        img.onload = function(){
          ctx.drawImage(img,500,0);
        }
      }

emoyee avatar May 30 '22 02:05 emoyee

Hey @emoyee - what exactly are you trying to do?

patrick-tolosa avatar May 30 '22 07:05 patrick-tolosa

根据下拉框选择不同的风格滤镜,图片会呈现不同的效果,但是effect渲染出来的url 上有点问题

emoyee avatar May 30 '22 08:05 emoyee

Hi @emoyee - Does effect definitely have the right value set? If you add a <span>Effect value: {{ effect }}</span> to your template, do you see the expected value printed?

aleksandar-cloudinary avatar May 30 '22 12:05 aleksandar-cloudinary

K0GP8HIP~PBD{K37ZP(13`3 It's still the same

emoyee avatar May 31 '22 02:05 emoyee

Hi @emoyee - Thanks for trying that. I went ahead and set up a quick app locally to try and reproduce. In my View I just have:

<template>
  <div>
    <h2>Test effect</h2>

    <div :set="effect='art:incognito'">
        <span>Effect value: {{effect}}</span>
    </div>

  <cld-image public-id="sample" background="yellow" width=150 height=150 crop="pad">
    <cld-transformation :effect="effect" />
  </cld-image>

  </div>
</template>

<script>
export default {
  name: "Test",
}
</script>

I use <div :set="effect = 'art:incognito'"> to create a variable effect that I then use further down in the <cld-transformation/>.

Once I run the app, I get the following output from this view and the issue is not reproducible on my side:

Screenshot 2022-05-31 at 23 28 16

May I please ask you to share a CodeSandbox, CodePen or a link to a repository which contains a Vue app with the minimum amount of code needed to reproduce the issue? We can then try to run that locally or in the online environment to see the issue.

aleksandar-cloudinary avatar May 31 '22 22:05 aleksandar-cloudinary

Thanks for your reply.I need this effect to be variable,the effect value is changed, but not rendered. Test project I have released on https://github.com/emoyee/testImg.

emoyee avatar Jun 01 '22 03:06 emoyee

Hello @emoyee, thank you for providing the github link.

I've created a codesandbox here: https://codesandbox.io/s/winter-cache-rsrgf8?file=/src/App.vue:0-1953 that has a working version outputting the expected effect to the console & reflecting on the rendered page. I changed the elements from an el-select / el-option to a normal select/option as the provided snippet was displaying text instead of the dropdown elements and added a couple of javascript lines to the provided snippet. Let me know if there are any clarifications needed or if anything is not as expected!

rnamba-cloudinary avatar Jun 01 '22 23:06 rnamba-cloudinary

Hi,@rikuoCloudinary.I tried this URL, but I also changed el-select to select in my project, and the rendered URL remains unchanged. image The code is exactly the same as that on the website. I tried to create a new project, but there was a problem that could not be solved, so I don't know if it was the problem of the project.

emoyee avatar Jun 06 '22 06:06 emoyee

Can you please share your updated code?

PixelCook avatar Jun 06 '22 12:06 PixelCook

<template>
  <div>
    <!-- :set="effect='art:incognito'" -->
    <div>
      <span>Effect value: {{ effect }}</span>
    </div>
    <div>
      <input type="file" @change="upload" />
      <cld-image :public-id="public_id" id="imgPic">
        <cld-transformation :effect="effect" />
      </cld-image>
    </div>
    <div>
      图片效果:
      <select @change="changeStyle" name="selectChoices" id="choices">
        <option value="黑白">黑白</option>
        <option value="模糊">模糊</option>
        <option value="复古">复古</option>
      </select>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      public_id: "",
      effect: "",
    };
  },
  methods: {
    upload: function (e) {
      var _this = this;
      // 获取当前上传的文件
      var files = e.target.files[0];
      // console.log(files);
      if (!e || !window.FileReader) return; // 判断是否支持FileReader
      let reader = new FileReader();
      reader.readAsDataURL(files); // 文件转换
      reader.onloadend = function () {
        const url = "https://api.cloudinary.com/v1_1/demo/image/upload";
        const formData = new FormData();
        formData.append("file", files);
        formData.append("upload_preset", "docs_upload_example_us_preset");
        fetch(url, {
          method: "POST",
          body: formData,
        })
          .then((response) => {
            return response.text();
          })
          .then((data) => {
            data = JSON.parse(data);
            _this.public_id = data.public_id;
            _this.effect = "art:incognito";
            // console.log(data);
          });
      };
    },
    changeStyle: function () {
      this.effect = "art:quartz"; // Statically setting the value
      var cloudinary = document.getElementById("imgPic");
      console.log("this.effect", this.effect);
      console.log("cloud", cloudinary);
    },
  },
};
</script>
<style>
/* div {
  margin: 20px;
} */
</style>

emoyee avatar Jun 07 '22 01:06 emoyee

After this effect is assigned a value, the value will not change. image This effect should become art:quartz, but nothing has changed.

emoyee avatar Jun 07 '22 01:06 emoyee

Change your event function to:

changeStyle: function (event) {
  
  this.effect = event.target.value; 

  var cloudinary = document.getElementById("imgPic");

  console.log("this.effect", this.effect);

  console.log("cloud", cloudinary);

},

PixelCook avatar Jun 07 '22 09:06 PixelCook

image Still like this.

changeStyle: function (event) {
      this.effect = event.target.value; 
      var cloudinary = document.getElementById("imgPic");
      console.log("this.effect", this.effect);
      console.log("cloud", cloudinary);

      // this.effect = "art:quartz"; // Statically setting the value
      // var cloudinary = document.getElementById("imgPic");
      // console.log("this.effect", this.effect);
      // console.log("cloud", cloudinary);
    }

emoyee avatar Jun 07 '22 09:06 emoyee

You have that value hard coded, _this.effect = "art:incognito";

PixelCook avatar Jun 07 '22 09:06 PixelCook

How can I change it? This needs an initial value, otherwise there will be errors.

emoyee avatar Jun 07 '22 10:06 emoyee

_this.effect = this.effect; Screen Shot 2022-06-07 at 13 28 35

PixelCook avatar Jun 07 '22 10:06 PixelCook

If so, the <cld-transformation effect="art:incognito"> will not change and will always render the default value.

      <cld-image :public-id="public_id" id="imgPic">
        <cld-transformation effect="art:incognito" />
      </cld-image>

emoyee avatar Jun 08 '22 01:06 emoyee

Reference this sandbox https://codesandbox.io/s/lively-wood-cerp8d?file=/src/App.vue

PixelCook avatar Jun 08 '22 08:06 PixelCook

The code is modified according to this sandbox, but this effect is still not rendered.I copied all the code directly. image

emoyee avatar Jun 08 '22 09:06 emoyee

@emoyee You'll need to perform a transformation on the image via the URL transformations for the effect to be reflected in the img src attribute.

https://cloudinary.com/documentation/image_transformations https://cloudinary.com/product_updates/cartoonify_effect

For example, in the case of the user selecting "Cartoonify"

The URL would need to change from

https://res.cloudinary.com/demo/image/upload/v1/docs_uploading_example/pic1_doe7kg to https://res.cloudinary.com/demo/image/upload/e_cartoonify:20/v1/docs_uploading_example/pic1_doe7kg

Since you are utilizing Vue, this can be accomplished through the Vue SDK https://cloudinary.com/documentation/vue_image_manipulation

rnamba-cloudinary avatar Jun 09 '22 19:06 rnamba-cloudinary

你好,有收到我回复的邮件吗?已经有几天了,我并没有看到回复,请问有什么进展吗?

------------------ 原始邮件 ------------------ 发件人: "cloudinary/cloudinary-vue" @.>; 发送时间: 2022年6月10日(星期五) 凌晨3:29 @.>; @.@.>; 主题: Re: [cloudinary/cloudinary-vue] <cld-transformation :effect="effect" />生成的url中effect无效 (Issue #162)

@emoyee You'll need to perform a transformation on the image via the URL transformations for the effect to be reflected in the img src attribute.

https://cloudinary.com/documentation/image_transformations https://cloudinary.com/product_updates/cartoonify_effect

For example, in the case of the user selecting "Cartoonify"

The URL would need to change from

https://res.cloudinary.com/demo/image/upload/v1/docs_uploading_example/pic1_doe7kg to https://res.cloudinary.com/demo/image/upload/e_cartoonify:20/v1/docs_uploading_example/pic1_doe7kg

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

emoyee avatar Jun 13 '22 02:06 emoyee

What current issues are you still needing help with?

PixelCook avatar Jun 13 '22 11:06 PixelCook

目前就只有那个effect得问题,别的没有了

emoyee avatar Jun 14 '22 01:06 emoyee

https://codesandbox.io/s/vue-effect-changes-cerp8d

Here yah go

PixelCook avatar Jun 14 '22 12:06 PixelCook

image 我把代码全部复制的,这是渲染出来的url,依旧不对

emoyee avatar Jun 15 '22 01:06 emoyee

Remember to set the effect before you load the image.

PixelCook avatar Jun 15 '22 07:06 PixelCook

设置了,还是渲染不上

emoyee avatar Jun 15 '22 07:06 emoyee

Screen Shot 2022-06-15 at 10 32 15

The example works. Not sure what you're missing. Feel free to share your updated code and I can take a look.

PixelCook avatar Jun 15 '22 07:06 PixelCook