非常简单PHP缩略图生成程序源代码

非常简单PHP缩略图生成程序源代码<br /> &lt;?<br /> $FILENAME=&quot;image_name&quot;;// 生成图片的宽度<br /> $RESIZEWIDTH=400;// 生成图片的高度<br /> $RESIZEHEIGHT=400;<br /> function ResizeImage($im,$maxwidth,$maxheight,$name){<br /> $width = imagesx($im);<br /> $height = imagesy($im);<br /> if(($maxwidth &amp;&amp; $width &gt; $maxwidth) || ($maxheight &amp;&amp; $height &gt; $maxheight)){<br /> if($maxwidth &amp;&amp; $width &gt; $maxwidth){<br /> $widthratio = $maxwidth/$width;<br /> $RESIZEWIDTH=true;<br /> }<br /> if($maxheight &amp;&amp; $height &gt; $maxheight){<br /> $heightratio = $maxheight/$height;<br /> $RESIZEHEIGHT=true;<br /> }<br /> if($RESIZEWIDTH &amp;&amp; $RESIZEHEIGHT){<br /> if($widthratio &lt; $heightratio){<br /> $ratio = $widthratio;<br /> }else{<br /> $ratio = $heightratio;<br /> }<br /> }elseif($RESIZEWIDTH){<br /> $ratio = $widthratio;<br /> }elseif($RESIZEHEIGHT){<br /> $ratio = $heightratio;<br /> }<br /> $newwidth = $width * $ratio;<br /> $newheight = $height * $ratio;<br /> if(function_exists(&quot;imagecopyresampled&quot;)){ www.phperz.com<br /> $newim = imagecreatetruecolor($newwidth, $newheight);<br /> imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);<br /> }else{<br /> $newim = imagecreate($newwidth, $newheight);<br /> imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);<br /> }<br /> ImageJpeg ($newim,$name . &quot;.jpg&quot;);<br /> ImageDestroy ($newim);<br /> }else{<br /> ImageJpeg ($im,$name . &quot;.jpg&quot;);<br /> }<br /> }<br /> <br /> if($_FILES['image']['size']){<br /> if($_FILES['image']['type'] == &quot;image/pjpeg&quot;){<br /> $im = imagecreatefromjpeg($_FILES['image']['tmp_name']);<br /> }elseif($_FILES['image']['type'] == &quot;image/x-png&quot;){<br /> $im = imagecreatefrompng($_FILES['image']['tmp_name']);<br /> }elseif($_FILES['image']['type'] == &quot;image/gif&quot;){<br /> $im = imagecreatefromgif($_FILES['image']['tmp_name']);<br /> }<br /> if($im){<br /> if(file_exists(&quot;$FILENAME.jpg&quot;)){<br /> unlink(&quot;$FILENAME.jpg&quot;);<br /> }<br /> ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME); www~phperz~com <br /> ImageDestroy ($im);<br /> }<br /> }<br /> ?&gt;<br /> &lt;img src=&quot;&lt;? echo($FILENAME.&quot;.jpg?reload=&quot;.rand(0,999999)); ?&gt;&quot;&gt;&lt;br&gt;&lt;br&gt;<br /> &lt;form enctype=&quot;multipart/form-data&quot; method=&quot;post&quot;&gt;<br /> &lt;br&gt;<br /> &lt;input type=&quot;file&quot; name=&quot;image&quot; size=&quot;50&quot; value=&quot;浏览&quot;&gt;&lt;p&gt;<br /> &lt;input type=&quot;submit&quot; value=&quot;上传图片&quot;&gt;<br /> &lt;/form&gt;<br /> &lt;/body&gt;<br /> &lt;/html&gt;
RangeTime:0.007827s
RangeMem:206.56 KB
返回顶部 留言