PHP jpeg image being saved as jfif by Chrome

1.2k Views Asked by At

I have a PHP site that generates images. Doesn't matter if I use GD or Imagick

header('Content-Type: image/jpeg'); 
imagejpeg($source);
$img = new Imagick($source);
$img->setImageFormat("jpeg");
header('Content-Type: image/'.$img->getImageFormat());
echo $img->getImageBlob();

The image gets correctly served in the browser. But when I try to right-click and download it, Chrome wants to save it as "jfif" file. I understand that jfif is the file format, but I would like Chrome to default save it as "jpg" file. How can I change my PHP code so that Chrome does that?

Note 1: Chrome does allow to default save the file as "jpg" file when it is served directly as jpg-file from my web space.

Note 2: Firefox by default allows to save all my images from the website as "jpg". This is the behaviour I like to have.

1

There are 1 best solutions below

4
On

Follow the below steps and check whether it's working or not.

  1. Launch Registry Editor using Windows Search or Windows key + R pop-up window opens and type Regedit and press enter.
  2. Navigate to HKEY_CLASSES_ROOT > MIME > Database > Content Type > image/jpeg
  3. In the right panel, double-click on the Extension key. Its value should read as .jfif.
  4. Change the value to .jpg and click Okay.
  5. Close the Registry Editor.

The change should be instant and you should now be able to save JPG files from the web in .jpg format as it should be.