PHP loads images in the correct sizes

I know this question is very common, but the main point in my question is that I want to know how facebook or some other sites upload their photos in the correct size. eg. if we upload an image of size: width: 1000px, height: 20px. then facebook updates the status updates with this drawing, but makes the image size small in the right ratio. its jus scales the image, but we can know that the image is very wide (my own word for very high width: P), where long images are also displayed with high accuracy.

PIC NUMBER 1

PIC NUMBER 2

I have included sample images above. how facebook calculates the ratio of size n to images and exits the chart, keeping the right sizes, but reducing them at the same time.

0
source share
2 answers

This code is pretty detailed, but may give you an idea of ​​how to calculate image sizes.

Parameters are the width of your source and the maximum width and height of the maximum size.

function image_resize_dimensions($source_width,$source_height,$thumb_width,$thumb_height)
{
  $source_ratio = $source_width / $source_height;
  $thumb_ratio = $thumb_width / $thumb_height;

  // Ratio is Taller
  if ($thumb_ratio > $source_ratio)
  {
    $result_height = $thumb_height;
    $result_width = $thumb_height * $source_ratio;
  }

  // Ratio is Wider
  elseif ($thumb_ratio < $source_ratio)
  {
    $result_width = $thumb_width;
    $result_height = $thumb_width / $source_ratio;
  }

  // Ratio the Same
  elseif($thumb_ratio == $source_ratio)
  {
    $result_height = $thumb_height;
    $result_width = $thumb_width;
  }

  return array('x'=>$result_width,'y'=>$result_height);

}
+1
source

I think there are several factors.

  • the main factor is the width of the content displayed in
  • original image width
  • whether you want to fill all the content with an image or not (Facebook does not work)

, 1000 . - 400 . , 200 . - ( ).

, , .

, , 16: 9 4: 3, , .

0

All Articles