how to get DPI value of an uploaded image using GDI library | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | |
Hey all,
I want to get the DPI value of uploaded image. Is there any way to get the dpi value of an uploaded image using GD Library.
Kindly help me out to sort out my problem as i will be very grateful to you guys.
kind regards,
Mohsin Rafique
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: how to get DPI value of an uploaded image using GDI library
I do not believe you are able to get the DPI via GD.
Mark.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library
I'm also not sure, which formats actually save a DPI value...
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
Then is there any algorithm/formula which find the DPI value of an uploaded image? If so then kindly tell me as if it will not happen then i will be really in big trouble.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library
the DPI value is something print devices care about. so only a very few formats (like .psd) save that value. I have not heard, that bitmap image formats (bmp, jpg, png, gif) save such data (why should they?).
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
Then there are websites which tells the dpi value of an uploaded image. Then how can they do that? For reference here is a website which tellls the dpi value of an uploaded image instantly once we uplaod an image Reference Website Link |  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library
do you mean that second area ("Format auswählen”)? that has nothing to do with DPI, that’s the output size (and according to that, the DPI value is calculated)
I should try first… nevertheless, the result is the same, the DPI value (aka quality) is calculated by dividing the pixel dimensions by the size dimensions.
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
No i am talking about Qualität: which comes once the image upload. It show that property in just under Auflösung: (Uploaded image area view section).
Just upload any picture and it will tells something about Auflösung, Qualität, Tonwert, Material, Format, Zuschnitt etc. In Qualität property it shows also the dpi value. I want to know how it calculate that dpi value.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library Quote:
Originally Posted by neovantage I want to know how it calculate that dpi value. dpi = pixels / size
note:
if you uplaod the same picture with different format settings, you’ll see different dpi values.
q.e.d.
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
One more thing which i want ti clear sir
pixel = width * Height;
and size is the given format on the website which is Format auswählen: or size is the actuall size of uploaded image which we get from getimagesize() function in php? Please ellaborate more the formula which you guide me. it will be really a great help from your end.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library Quote:
Originally Posted by neovantage One more thing which i want ti clear sir
pixel = width * Height; wrong Quote:
Originally Posted by wikipedia In digital imaging, a pixel (or picture element) is the smallest item of information in an image. Quote:
Originally Posted by neovantage and size is the given format on the website which is Format auswählen: or size is the actuall size of uploaded image which we get from getimagesize() function in php? Please ellaborate more the formula which you guide me. it will be really a great help from your end. obviously* the size comes from "Format auswählen” (since that is the only option providing you with a length unit).
* – basic scientific deduction gives:
DPI = Dots Per Inch, Quote:
Originally Posted by wikipedia Dots per inch (DPI) is a measure of spatial printing or video dot density, in particular the number of individual dots that can be placed within the span of one linear inch (2.54 cm). The DPI value tends to correlate with image resolution, but is related only indirectly. - Dot is the smallest printable unit
- Inch is a size (length) dimension, can be converted into mm, cm, dm, m, km, ft, yd, mi (…)
- there is no definition of the size of a pixel (see above)
If you set Dot = Pixel (aka PPI) Quote:
Originally Posted by wikipedia PPI can also describe the resolution, in pixels, of an image to be printed within a specified space. […] Good quality photographs usually require 300 pixels per inch when printed. you get (according to the unit) the formula:
DPI = pixels (Dots) / (Per) size (Inch)
Q.E.D
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
Some one share code on youtube to get DPi value of an image.
Do you think it is good. here is the code -
function get_dpi($filename){
-
// open the file and read first 20 bytes.
-
$a = fopen($filename,'r');
-
$string = fread($a,20);
-
fclose($a);
-
// get the value of byte 14th up to 18th
-
$data = bin2hex(substr($string,14,4));
-
$x = substr($data,0,4);
-
$y = substr($data,4,4);
-
return array(hexdec($x),hexdec($y));
-
}
-
// output the result:
-
print_r(get_dpi('filename.jpg'));
-
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library
this has clearly nothing to do with DPI.
the function returns 2 (!) values, internally named $x and $y (!) (image dimension). so, how is that the single DPI value?
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
Hmm ok.
I have write php code for dpi code now as you guide me. So will please tell me that is it right or wrong. -
//My uploaded image resolution is 850 x 567
-
$pixels = 481950;
-
// my select format is 30 x 20 cm
-
$inch_first = 30 / 2.54;
-
$inch_second = 20 / 2.54;
-
$inch = $inch_first * $inch_second;
-
$DPI = $pixels /$inch;
-
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library
this would be the squared DPI. if picture and format are similar (i.e. the width/height ratio is the same) you just need to take the square root. otherwise you have to calculate the vertical and horizontal DPI values separately.
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
And how can i calculate the verticle and horizental DPI values seperately as the appliaction i am working on most of the people never give the picture as per predefined format say selected format is 30 x 20 cm.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library
get the width & height of the image.
determine wether it is portrait or landscape.
DPI (horizontal) = image width / format width
DPI (vertical) = image height / format height
if picture and format are not similar, you have to crop the image (or print canvas)
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library Quote:
get the width & height of the image.
determine wether it is portrait or landscape.
DPI (horizontal) = image width / format width
DPI (vertical) = image height / format height
I have find out the DPI (horizontal) and DPI (vertical) but how can i actaully show one single dpi of an image?
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library Quote:
Originally Posted by neovantage how can i actually show one single dpi of an image? not at all.
DPI is related to printing not to images (as the wikipedia article points out).
even text has a DPI value when printed and what is a “single dpi” of the text?
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
Hmm ok
But can you tell me how this website Link finding the dpi value of uploading images against selected "Format auswählen"?
As i need to do that in my client appliction and i am stuck with that. Please please help me out to sort out my problem
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: how to get DPI value of an uploaded image using GDI library Quote:
Originally Posted by neovantage Hmm ok
But can you tell me how this website Link finding the dpi value of uploading images against selected "Format auswählen"?
As i need to do that in my client appliction and i am stuck with that. Please please help me out to sort out my problem They're not finding the DPI of an image. They have set widths that you select from and, I assume, that value is then passed to a printer.
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
Printer in a sense means? And if it connects to a printer then how it returns the dpi value of that particular uploaded image?
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library
don’t mistake PPI for DPI (like on that website).
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
I didnt get you sir. Please ellaborate it in more details as i asked different question and what is that PPI?
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library
see post #11
_______________
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
Thanks but how what's the formula then to calculate the PPI value of an uploaded image and my 2nd question posterlia.de means finding the PPI value sof an uploaded image instead od DPI value am i right?
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library Quote:
Originally Posted by neovantage Thanks but how what's the formula then to calculate the PPI value of an uploaded image see post #17
_____________
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library Quote:
Originally Posted by neovantage my 2nd question posterlia.de means finding the PPI value sof an uploaded image instead od DPI value am i right? the point is that hardly any user has ever heard off PPI, but DPI as a resolution value is known.
another example: if I were to explain the molecular structure of ammonia (NH3), I’d go for the VSEPR model, although I know that many aspects are incorrect. explaining the phosphane (PH3) structure (and comparing it with ammonia) I had to use the correct, but rather difficult MO theory.
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library I have done that already but it is giving me the DPI's horizentally and vertically seperately. I need to show the DPi value of the image. Not specifically horizentally or vertically respectively.
Here is my code which i have done that seperately. -
$sizes[0] = intval($sizes[1]); // Having height selected of Format auswählen
-
$sizes[1] = intval($sizes[0]); // Having width selected of Format auswählen
-
-
if($sizes[0]>$sizes[1]){ //
-
$DPIRandom_w = $o_wd / $sizes[0];
-
$DPIRandom_h = $o_ht / $sizes[1];
-
}else{
-
$DPIRandom_w = $o_wd / $sizes[1];
-
$DPIRandom_h = $o_ht / $sizes[0];
-
}
-
$DPIRandom_w = $o_wd / $sizes[0];
-
Here is the url of my application Link
Just upload an image n you will have the results. but i need to show 1 single value sir like posterlia.de.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library Quote:
Originally Posted by neovantage but i need to show 1 single value sir like posterlia.de. take ther smaller one. or insert canvas then you can take the larger one
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library Quote:
take ther smaller one.
Does it means smaller value from DPI (horizontal) or DPI (verticle) Quote:
or insert canvas then you can take the larger one
I didnt get that.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library Quote:
Originally Posted by neovantage Does it means smaller value from DPI (horizontal) or DPI (verticle) *sigh* yes Quote:
Originally Posted by neovantage I didnt get that. what do you do in case the chosen format is 30x20 cm and the picture is 400x200 px?
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
Sir
if my picture is of 400x200 and my selected format is 30x20cm then i get the values of DPI (horizontal) and DPI (verticle) by divding 400/30 and 200/20 respectively. So this is all i do and i get the DPI values of horizentally and vertically. This is all i do.
*note: if 30 greater than 20 then i divide 400 by 30 and 200 by 20 and vice versa
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
Sir Dormilich,
where are you please help me out. I am badly stuck in it and i have less time. Pleaseeeeeeeee do something for me i will be really very grateful to you
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library
where are you stuck?
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
Sir you asked question from me Quote:
what do you do in case the chosen format is 30x20 cm and the picture is 400x200 px?
And i answered that Quote:
Sir
if my picture is of 400x200 and my selected format is 30x20cm then i get the values of DPI (horizontal) and DPI (verticle) by divding 400/30 and 200/20 respectively. So this is all i do and i get the DPI values of horizentally and vertically. This is all i do.
*note: if 30 greater than 20 then i divide 400 by 30 and 200 by 20 and vice versa
But i am still unable to get the single DPI value as porterlia.de website calculating.
This is my website URL where i am acalculating DPi value but these are horizental and verticle as you suggested the formula. it gives 2 seperate values. I need one single value sir
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library
well. starting with posterlia.de. they do exactly calculate as expected. if I upload a picture (520x824) in 30 x 20 cm (vertical 69.8, horizontal 66.0), they correctly calculate a value of 70 ppi.
ranaposter.de however calculates 72 ppi (rounded to the next standard resolution, I suppose)
you calculate vertical 41.2, horizontal 17.33, that doesn’t even have the right width-height-ratio. I have no idea how you get those results.
EDIT: I have an idea. you forgot two things. - determine whether it’s portrait or landscape
- centimeters are not inches
| | Familiar Sight | | Join Date: Aug 2008
Posts: 175
| | | re: how to get DPI value of an uploaded image using GDI library
Sir here is my code. -
<?
-
if($sizes[0]>$sizes[1]){
-
//echo "Width of actauly uploaded image: ".$o_wd ;
-
//echo "height of actauly uploaded image: ".$o_ht;
-
//echo "Width of selected format image: ".$sizes[0];
-
//echo "height of selected format image: ".$sizes[1];
-
$DPIRandom_w = $o_wd / $sizes[0];
-
$DPIRandom_h = $o_ht / $sizes[1];
-
}else{
-
//echo "Width of actauly uploaded image: ".$sizes[1];
-
//echo "height of actauly uploaded image: ".$sizes[0];
-
//echo "height of selected format image: ".$sizes[0];
-
//echo "Width of selected format image: ".$sizes[1];
-
$DPIRandom_w = $o_wd / $sizes[1];
-
$DPIRandom_h = $o_ht / $sizes[0];
-
}
-
?>
-
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: how to get DPI value of an uploaded image using GDI library
all I can say is that ranaposter fails to do the format detection (a landscape image is calculated correctly*, a portrait image is not)
* see previous post, EDIT section
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,272 network members.
|