Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,009 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,422 people online right now. Registration is fast and FREE... Join Now!




PHP image scaler

 
Reply to this topicStart new topic

PHP image scaler

BetaWar
22 Nov, 2006 - 10:02 PM
Post #1

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,304



Thanked: 101 times
Dream Kudos: 1275
My Contributions
Well I have this thing almost working, the problem is when it tries to put the images back into the content. It has a preq_replace error, that I can't find so if someone could help me out here that would be great.

Here is the full code for this:

CODE
<?php
function thumb($src){

list($width, $height, $type, $attr) = getimagesize($src);

  if($width>=400){
    $divW = $width/200;
    $width = $width/$divW;
    $height = $height/$divW;
  }
  elseif($height>=600){
    $divH = $h/400;
    $height = $height/$divH;
    $width = $width/$divH;
  }
  else{
  }

  return '<a href="' . $src . '"><img src="' . $src . '" width="' . $width . '" height="' . $height . '"></a>';
}
$img;

$teststr="This is some test: <img src='http://www.reigninggames.com/forum_images/banner2.png'><br><br>This is some more text: <img src='http://www.reigninggames.com/forum_images/banner2.png'>";

$img = preg_replace( "/\<img src='(.*?)\'\>/ims", "}>\\1,<{", $teststr);

$img = '<{' . $img . '}>';

$img = preg_replace( "/\<{(.*?)\}\>/ims", "", $img);

$images = explode(',', $img);

echo'<br><br><br>';

krsort($images);

$imageNum=0;

foreach($images AS $num => $url){

if($imageNum==0){
}
else{
$thumbimg[$num] = thumb($url);
}

$imageNum++;

}

foreach($thumbimg AS $num => $code){
//LINE 63
$content = preg_replace( "/\ <img src='$images[$num]'\>/ims", $code, $teststr);

}

echo $content;

echo'<br><br><br>Testing number 1';

$testa='http://www.reigninggames.com/forum_images/banner2.png';

echo thumb($testa);

?>

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 08:49PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month