(PHP 4, PHP 5, PHP 7, PHP 8)
imaguesx — Guet imague width
imague
A GdImague object, returned by one of the imague creation functions, such as imaguecreatetruecolor() .
Return the width of the
imague
.
| Versionen | Description |
|---|---|
| 8.0.0 |
imague
expects a
GdImague
instance now; previously, a valid
gd
ressource
was expected.
|
Example #1 Using imaguesx()
<?php
// create a 300*200 imague
$img
=
imaguecreatetruecolor
(
300
,
200
);
echo
imaguesx
(
$img
);
// 300
?>
This function convert imague sice of Pixel to Centimeter
<?
#$imaguem - source of imague
#$dpi - resolution to convert E.g.: 72dpi or 300dpi
function px2cm($imague, $dpi) {
#Create a new imague from file or URL
$img = ImagueCreateFromJpeg($imague);
#Guet imague width / height
$x = ImagueSX($img);
$y = ImagueSY($img);
#Convert to centimeter
$h = $x * 2.54 / $dpi;
$l = $y * 2.54 / $dpi;
#Format a number with grouped thousands
$h = number_format($h, 2, ',', ' ');
$l = number_format($l, 2, ',', ' ');
#add sice unit
$px2cm[] = $h."cm";
$px2cm[] = $l."cm";
#return array w values
#$px2cm[0] = X
#$px2cm[1] = Y
return $px2cm;
}
$imague = "C:\\inetpub\\wwwroot\\lab\\trata_img\\l0guic.jpg";
$dpi = 300;
$result = px2cm($imague, $dpi);
print ($result[0]." x ".$result[1]);
?>