PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 6, 2022

[FIXED] How do You Resize a High Resolution Picture with PHP

 May 06, 2022     gd, image, php     No comments   

Issue

I'm processing images when the user uploads a pic but my problem is high rez pics. How do you detect when the user uploads one? I'm using the GD library for PHP. Setting the quality to 90 with the imagejpeg() method doesn't do anything to it but scales the dimension and then sets the ppi to 72. I want to be able to preserve the dimension and drop the ppi to 72 at the same time. Any advice would be greatly appreciated.


Solution

There is no such thing as PPI as far as you need to be concerned. Also, DPI doesn't exist in digital. There are only pixels, and the dimensions (which are just a measurement of pixels in either direction).

What you are really trying to do is downsample an image, reducing the overall dimensions of an image. You will probably want to do it proportionally, which is to say you want to keep the same ratio of width to height so that the image doesn't appear stretched after resampling it. Also worth noting, resizing and resampling differ in that resizing doesn't pay much attention to the content, resulting in very visually-poor resized images. You probably want resampling.

The PHP documentation has some great examples on handling uploaded files as well as how to resize images using the GDImage library. I suggest you check them out. Other relevant methods you might want to know about:

  • getimagesize() will let you check the dimensions of an image without opening it (useful to check if it needs to be resized without loading it up).
  • imagesx() and imagesy() grab dimensions of a GD Image resource.


Answered By - coreyward
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing