<?php

$img = '<img src="http://w...content-available-to-author-only...t.no/bilde.jpg" width="2000" height="1400" />'; 

$doc = new DOMDocument; 
$doc->loadHTML($img); 

$node   = $doc->getElementsByTagName("img")->item(0); 
$height = intval($node->getAttribute('height')); 
$width  = intval($node->getAttribute('width')); 

if ($width > 1000) { 
    $oldwidth = $width; 
    $width    = 1000; 
    $ratio    = $width / $oldwidth; 
    $height   = $height * $ratio; 
} elseif ($width < 500) { 
    $oldwidth = $width; 
    $width    = 500; 
    $ratio    = $width / $oldwidth; 
    $height   = $height * $ratio; 
} 

$node->setAttribute('height', intval($height)); 
$node->setAttribute('width', intval($width)); 

$img = $doc->saveHTML($node);

echo $img;

?>