9951 explained code solutions for 126 technologies


php-gdHow to get image size from resource


<?php

$file = '/var/www/examples/heroine.png';
$size = getimagesize($file);
$im = imagecreatefrompng($file);

$width  = imagesx($im);
$height = imagesy($im);ctrl + c
$im

image resource to get size of

imagesx

returns width of given image

imagesy

returns height of given image


Usage example

<?php

$file = '/var/www/examples/heroine.png';
$size = getimagesize($file);
$im = imagecreatefrompng($file);

$width  = imagesx($im);
$height = imagesy($im);

echo $width . 'x' . $height;
output
733x1100