ascorbic / unpic

Universal image CDN translator
https://unpic.pics/lib
277 stars 30 forks source link

How can I display private domain cdn images? #129

Open jderboven opened 3 months ago

jderboven commented 3 months ago

Hello,

I'm trying to useimport { Image } from '@unpic/react/nextjs';

My source comes from a private domain on my customer network, how can I disable cdn check so that my image is well displayed ? For now it comes with next/image and the url is encoded

Thanks for help

ascorbic commented 3 months ago

I don't fully understand. Are you using an image CDN? Is the private domain an image CDN or just static images?

jderboven commented 3 months ago

Actually that’s just a remote url on the customer network m not a static img

ascorbic commented 3 months ago

OK, can you explain exactly:

jderboven commented 3 months ago

Ok what I would like is the following :

What happens : the image link gets decoded and put above some srcset like a normal next image with optimization. What is rendered : nothing as it gets decoded and the link cannot be found The code :

'use client';

import { blurhashToCssGradientString } from '@unpic/placeholder';
import { Image } from '@unpic/react/nextjs';

type ImageNextProps = {
  layout: 'fixed' | 'fullWidth' | 'constrained';
  src: string;
  alt: string;
  blurHash?: string;
  className?: string;
};

export const ImageNext = (props: ImageNextProps) => {
  const { layout, src, alt, blurHash = 'LEHV6nWB2yk8pyo0adR*.7kCMdn4', className = '' } = props;

  const placeholder = blurhashToCssGradientString(blurHash);

  return (
    <Image
      src={src}
      alt={alt}
      layout={layout}
      className={`image-next ${className}`}
      background={placeholder}
    />
  );
};