-
October 13th, 2008, 04:15 AM
#1
Member
PHP image resize
I'm having some issues putting 2 pieces of code together
First part
I have this string
$string = "some text... <img src=myimage.jpg> some more text <img src=myimage.jpg>";
What i want to do is add width and height to those img tags and automatically reduce the image size by like 50%. I have a function that returns the image width and height in an array. For example
$resized_image = imgresize("path to image");
I then can print $resized_image[height] to get the height, and $resized_image[width] for the width.
Second part
I have a reg exp that will search for the image tag and add width and height
Code:
$pattern = "/(<img\s+).*?src=((\".*?\")|(\'.*?\')|([^\s]*)).*?>/is";
$replacement = "<img src=$2 width=$resized_image[width] height=$resized_image[height]>";
echo preg_replace($pattern, $replacement, $string);
How can i tie these 2 together? The only way i can think of is to call the array in the $replacement string, but dont know how to do so with an array
Similar Threads
-
By grindcore in forum Web Security
Replies: 0
Last Post: August 30th, 2007, 04:33 AM
-
By nightcat in forum The Security Tutorials Forum
Replies: 9
Last Post: May 28th, 2005, 02:47 AM
-
By Vorlin in forum Other Tutorials Forum
Replies: 3
Last Post: June 15th, 2004, 10:25 PM
-
By HDD in forum Other Tutorials Forum
Replies: 2
Last Post: February 1st, 2004, 08:05 PM
-
By GreekGoddess in forum The Security Tutorials Forum
Replies: 19
Last Post: August 28th, 2003, 06:07 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|