set image width with php?
<p>I am creating a custom blog with php. when the user is uploading an article I am having problem  with the images in the post. some images's width are bigger than the main div in my blog (740). I want to use php to check the width of the images if it is bigger than 740 then re-size  the image to 740.</p>

<pre><code>&lt;?php
$dom = new domDocument;
$dom-&gt;loadHTML($article_content);
$dom-&gt;preserveWhiteSpace = false;
$imgs  = $dom-&gt;getElementsByTagName("img");
$links = array();

for($i=0;$i&lt;$imgs-&gt;length;$i++){
$links[]  = $imgs-&gt;item($i)-&gt;getAttribute("width");
$image_path = $links[];
$article_source = imagecreatefromstring(file_get_contents($image_path));
$image_width = imagesx($image_source);
if($image_width &gt; 740){$image_width = 740;}      
}   

?&gt;
</code></pre>

<p>so far this is the code that I have. I am not sure how to set the image width.(the image already has its original width)
UPDATE:
I am not trying to save or copy the image. I am trying to access the dom by php and set the image width to $image_width (of all images)</p>
