Jump to content

Resize Image


maxudaskin

Recommended Posts

Ok, before you think, oh wow, this guy doesn't know anything, I do know how to do it, but, I am stuck on a method for a code I made.

 

<?php
/* FORUM ARRAYS */
$find   = array("[img]",
"[/img]");
$replace = array("<img src=\"","\" />");
?>

 

<?php
echo str_replace($find,$replace,nl2br($textsql['text']));
?>

 

What I want it to do is after it changes [ img ] and [ /img ] to <img src=\" and \" /> for it to check the image size, probably with

<?php
$getimg = getimagesize("somepic.jpg");
list($width, $height, $type, $size) = $getimg;
?>

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

haha well you had me confused title of thread said resize image. well there are many different ways to do it i suppose but heres a way with preg_match_all

<?php
$text = "GLAD to see we have our new forum! [img=http://www.url.com/image.jpg] GLAD to see we have our new forum! ";

preg_match_all('/\[img\](.*?)\[\/img\]/', $text, $get, PREG_PATTERN_ORDER);

//complete tag and url
echo $get[0][0];

echo "<br><br>";
//url only
echo $get[1][0];

?>

Link to comment
https://forums.phpfreaks.com/topic/98729-resize-image/#findComment-505329
Share on other sites

Why don't you test it? You could always use preg_replace_callback like so

 

<?php

// This is a very loose regex for example purposes only.
// For production use, it should be santizied and cleaned
// unless the source of input is from a trusted source

$regex = '%\[img\]([^\[]++)\[/img\]%i';

$subject = 'This is some text and this: [img=img.jpg] will be converted to proper code';

$result = preg_replace_callback(
$regex,
create_function('$matches', '
	if (!$img = getimagesize($matches[1]) )
		return FALSE;
	if (!$img[0] || !$img[1])
		return FALSE;
	return "<img src=\"$matches[1]\" width=\"$img[0]\" height=\"$img[1]\" />";
'),
$subject
);

echo $result;

?>

Link to comment
https://forums.phpfreaks.com/topic/98729-resize-image/#findComment-506043
Share on other sites

I got an error with your code...

 

Warning: getimagesize(images/TOPLOGO.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/.grable/vzoom/virtualzoom.net/Untitled-1.php(19) : runtime-created function on line 2

This is some text and this: will be converted to proper code

Link to comment
https://forums.phpfreaks.com/topic/98729-resize-image/#findComment-506109
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.