Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.