Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Get image width using url of the image

Go to End

3 Posts   1282 Views


Community Member, 8 Posts

21 September 2013 at 11:40pm

Edited: 21/09/2013 11:41pm

I am trying to get the image width from the url of the image. Is that possible ??
What i am trying to do is, if a user uploads image from the editor and if the width of image uploaded is greater than 700px then i will resize the image and use that in place of the original one. I am grabbing all the images in the editor like this

$doc = new DOMDocument();
$imageTags = $doc->getElementsByTagName('img');
foreach($imageTags as $tag) {
$imgs = $tag->getAttribute('src');
echo "<img src='/$imgs' />";

Now how can i check the width of these image ??
Please help me I am stuck...


Community Member, 254 Posts

23 September 2013 at 6:36pm

Hi Sultan,
You wont be able to do it via the URL. You'll need to actually load the image first to read that property. Unless of course you control the HTML you could output it in the <img> tag.

To do this yourself first load the image with imagecreatefromjpeg
then read width with getimagesize
It'll be the first item in the array of getimagesize.


$image = imagecreatefromjpeg( '' );
$dimensions = null;
getimagesize( $image, $dimensions );
echo 'width = ' . $dimensions[0];

I haven't tested the code, you may need to write the file first....


Community Member, 8 Posts

23 September 2013 at 11:40pm

Thanks Bambii7 for your reply. I tried the examples in the link provided by you. But width and height is coming blank.

Can u please share a working example.