export const resizeImage = (file, callback) => {
  const img = new Image();
  img.src = URL.createObjectURL(file);
  let width = 1500;
  let height = 1500;
  img.onload = () => {
    // if (width > height) {
    //   if (width > 3000) {
    //     height = Math.round(height / 2);
    //     width = 3000;
    //   }
    // } else {
    //   if (height > 3000) {
    //     width = Math.round(width / 2);
    //     height = 3000;
    //   }
    // }

    const canvas = document.createElement("canvas");
    canvas.width = width;
    canvas.height = height;

    const ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0, width, height);

    canvas.toBlob(
      (blob) => {
        const reader = new FileReader();
        reader.onloadend = () => {
          callback(reader.result);
        };
        reader.readAsDataURL(blob);
      },
      file.type,
      0.8
    );
  };
};
