Jump to content

bbcode resize image


vividona

Recommended Posts

I am trying to replace image code and resize it at the same time

but gave me error.

Warning: getimagesize($1): failed to open stream: No such file or directory in C:\wamp\www\ . . . . .

 


public function resize_Images($originalImage,$toWidth,$toHeight){
    
    // Get the original geometry and calculate scales
    list($width, $height) = getimagesize($originalImage);
    $xscale=$width/$toWidth;
    $yscale=$height/$toHeight;
    
    // Recalculate new size with default ratio
    if ($yscale>$xscale){
        $new_width = round($width * (1/$yscale));
        $new_height = round($height * (1/$yscale));
    }
    else {
        $new_width = round($width * (1/$xscale));
        $new_height = round($height * (1/$xscale));
    }

    // Resize the original image
    $imageResized = imagecreatetruecolor($new_width, $new_height);
    $imageTmp     = imagecreatefromjpeg ($originalImage);
    imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    return $imageResized;
}

public function bhl_bbcodes($str) { 
  
    $simple_search = array(  
                '/\[img\](.*?)\[\/img\]/is', 
    );  
  
    $simple_replace = array(  
			'<img src="'.$this->resize_Images('$1', 700, 500).'" />',
);
    $str = preg_replace ($simple_search, $simple_replace, $str);   
  
    return $str;
}

Link to comment
https://forums.phpfreaks.com/topic/247386-bbcode-resize-image/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.