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
38 13770
I do not believe you are able to get the DPI via GD.
Mark.
I'm also not sure, which formats actually save a DPI value...
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.
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?).
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
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.
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.
@neovantage
dpi = pixels / size
note:
if you uplaod the same picture with different format settings, you’ll see different dpi values.
q.e.d.
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.
@neovantage
wrong
In digital imaging, a pixel (or picture element) is the smallest item of information in an image.
@neovantage
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,
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)
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
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'));
-
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?
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;
-
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.
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.
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)
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?
@neovantage
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?
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
@neovantage
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.
Printer in a sense means? And if it connects to a printer then how it returns the dpi value of that particular uploaded image?
don’t mistake PPI for DPI (like on that website).
I didnt get you sir. Please ellaborate it in more details as i asked different question and what is that PPI?
see post #11
_______________
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?
@neovantage
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.
see post #17
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.
@neovantage
take ther smaller one. or insert canvas then you can take the larger one
take ther smaller one.
Does it means smaller value from DPI (horizontal) or DPI (verticle)
or insert canvas then you can take the larger one
I didnt get that.
@neovantage *sigh* yes @neovantage
what do you do in case the chosen format is 30x20 cm and the picture is 400x200 px?
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
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
Sir you asked question from me
what do you do in case the chosen format is 30x20 cm and the picture is 400x200 px?
And i answered that
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
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
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];
-
}
-
?>
-
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
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
reply
views
Thread by Mark |
last post: by
|
2 posts
views
Thread by bissatch |
last post: by
|
reply
views
Thread by Satish Appasani |
last post: by
|
5 posts
views
Thread by IkBenHet |
last post: by
|
2 posts
views
Thread by Brad |
last post: by
|
3 posts
views
Thread by Senthil |
last post: by
|
14 posts
views
Thread by =?Utf-8?B?U2FtdWVs?= |
last post: by
| | | | | | | | | | | | |