Search code examples
phpimage-processingjpegscale

Scale Images in PHP


for a project i have to do the folliwing things:

  • check if a file is a valid image (JPEG, and if possible more formats)
  • check width/height of an image (JPEG, and if possible more formats)
  • scale an image (JPEG, and if possible more formats)

it´s forbidden to use external frameworks or scripts. only php-functions or self-written code are allowed.

so how is it possible with php?


Solution

  • 1. For the MIME Type getimagesize(); returns that. mime is the correspondant MIME type of the image. This information can be used to deliver images with the correct HTTP Content-type header:.

    2 . See the getimagesize();

    Returns an array with 7 elements. Index 0 and 1 contains respectively the width and the height of the image.

    3. ImageMagick also does that effectively.