首页 > 解决方案 > Cloudinary React component not rendering width or height transformation to URL

问题描述

I'm integrating Cloudinary into my React app at the moment. I want to display images at 300px height (automatic width), and set format and quality to auto. Here's my component:

import React from 'react'
import {Image, Video, Transformation, CloudinaryContext} from 'cloudinary-react';

const AddContent = () => {
  return (
    <div id="add-content">
      <CloudinaryContext cloudName="mycloudname">
        <Image publicId="samples/food/spices">
          <Transformation height={300} quality="auto" fetchFormat="auto" />
        </Image>
      </CloudinaryContext>
    </div>
  );
}

export default AddContent;

This is resulting in the following image tag:

<img src="http://res.cloudinary.com/mycloudname/image/upload/f_auto,q_auto/v1/samples/food/spices">

So, the f_auto and q_auto are fine, but it's missing the h_300 tag.

标签: reactjsimage-manipulationcloudinary

解决方案


调整大小时,您需要添加“裁剪”模式。尝试 -

<Transformation height={300} crop="scale" quality="auto" fetchFormat="auto" />

推荐阅读