0

I am trying to make different resolutions of same image (like 1080x1920 , 1280x720 , 1920x1080 etc ).I am using the GD library of php. I am able to get the desired resolution (i.e 1080x1920) but the original image(1080x1920) is shrinked in the new image. original picture , Picture that I am getting , Desired output

Here is my code

<?php 
    $old_img_path="ironspider-xq.jpg";
    $t = imagecreatefromjpeg("$old_img_path");
    $s = imagecreatetruecolor(1080, 1920);
    $x = imagesx($t);
    $y = imagesy($t);
    imagecopyresampled($s, $t, 0, 0, 0, 0, 1080, 1920, $x, $y);
    imagejpeg($s, "1080x1920-ironspider-xq.jpg");
    $new_img_path= "1080x1920-".$old_img_path;
?>
kyle
  • 1
  • 1
    If you want to go from `original picture` to `Desired output`, you can't just resize -- you need to cut the edges off and keep only the center strip. See `imagecrop()`. – Alex Howansky Apr 18 '21 at 19:14
  • Does anybody know how the wallpapers sites produce different resolutions of same image. Do they use php or do it manually for each image? – kyle Apr 18 '21 at 20:45
  • Producing different resolutions of the same image is easy to automate if the aspect ratio doesn't change, which it typically doesn't for wallpapers. You're trying to rotate from 1920x1080 to 1080x1920, which dramatically changes the aspect ratio and adds the requirement that you crop. – Alex Howansky Apr 18 '21 at 21:14

0 Answers0