473,411 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

How to resize large images ???

3
HtmlString includes a web page, and soon it is converted to Html file.
In the web page, they are images, and some of them are large. They are so large, in fact they are going to destroy my Tables, so I need to resize these images.

I write a Function to do this job.

[COLOR=DarkOrange]Resizeimage(HtmlString)[/COLOR]

[COLOR=SeaGreen]Function Resizeimage(ConStr)
Dim TempStr,Re,Matches,Match,Tempi,TempArray

Set Re = New Regexp
Re.IgnoreCase = True
Re.Global = True
Re.Pattern ="<img.+?[^\>]>"
Set Matches =Re.Execute(ConStr)

For Each Match in Matches
If TempStr<>"" then
TempStr=TempStr & "$Array$" & Match.Value
Else
TempStr=Match.Value
End if
Next
If TempStr<>"" Then
TempArray=Split(TempStr,"$Array$")
TempStr=""
For Tempi=0 To Ubound(TempArray)


Re.Pattern ="src\s*=\s*.+?\.(gif|jpg|bmp|jpeg|psd|png|svg|dxf |wmf|tiff)"
Set Matches =Re.Execute(TempArray(Tempi))
For Each Match in Matches
If TempStr<>"" then
TempStr=TempStr & "$Array$" & Match.Value
Else
TempStr=Match.Value
End if
Next
Next
End if

If TempStr<>"" Then
Re.Pattern ="src\s*=\s*"
TempStr=Re.Replace(TempStr,"")
End If

Set Matches=nothing
Set Re=nothing

If TempStr="" or IsNull(TempStr)=True Then
ReplaceSaveRemoteFile=ConStr
Exit function
End if

TempStr=Replace(TempStr,"""","")
TempStr=Replace(TempStr,"'","")
TempStr=Replace(TempStr," ","")


Dim PathTemp

TempArray=Split(TempStr,"$Array$")
TempStr=""
For Tempi=0 To Ubound(TempArray)
If Instr(Lcase(TempStr),Lcase(TempArray(Tempi)))<1 Then
TempStr=TempStr & "$Array$" & TempArray(Tempi)
End If
Next
TempStr=Right(TempStr,Len(TempStr)-7)
TempArray=Split(TempStr,"$Array$")

Set Re = New Regexp
Re.IgnoreCase = True
Re.Global = True

For Tempi=0 To Ubound(TempArray)
Re.Pattern =TempArray(Tempi)
PathTemp=TempArray(Tempi)

PathTemp=PathTemp&"' onclick='javascript:window.open(this.src);' onload='javascript:if(this.width>screen.width-300)this.style.width=screen.width-300;"
ConStr=Re.Replace(ConStr,PathTemp)

Next
Set Re=nothing

Resizeimage=ConStr
End function[/COLOR]

this founction works well with the first few files,but I met problem soon.
Aug 18 '05 #1
2 3487
xain
3
this function deal with this kind [COLOR=Navy]<img src='xxxx/2005081723/20050817234741716.jpg'/>[/COLOR] images well.
but not this one:
[COLOR=Navy]<img src="xxxx/2005081723/20050817234741716.jpg"/>[/COLOR] (with ")

nor this one:
[COLOR=Navy]<img src='xxxx/2005081723/20050817234741716.jpg' onload="javascript:if(this.width>screen.width-300)this.style.width=screen.width-300;"/>[/COLOR] (with resize script already)

How can I improve my function to fit these codes?
Or do you have any better solution?
Aug 18 '05 #2
xain
3
I find this simpler Function:
[COLOR=DarkOrchid]Function bbimg(strText,ssize)
Dim Re
Set re=new RegExp
re.IgnoreCase =True
re.Global=True
Dim s
s=strText
re.Pattern="<img(.[^>]*)>"
s=re.replace(s,"<img$1 onclick=""javascript:window.open(this.src);"" onload=""javascript:if

(this.width>screen.width-"&ssize&")this.style.width=screen.width-"&ssize&";"">")
bbimg=s
End Function[/COLOR]
Aug 19 '05 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: rams.kakara | last post by:
hi, My page have background image,on that image have more images and text. My problem is whenever resize browser that images are not resized and also not moved correct place .(i.e look not like...
6
by: David Hayes | last post by:
juglesh <juglesh@nospamRadioKDUG.com> wrote in "Re: how to maximize the browser window that fits the monitor size?" (Saturday, January 01, 2005 3:12 AM): > > >I want to maximize the browser...
4
by: SlasherStanley | last post by:
BlankHi How do you resize a jpg file. I want to open a file (c:\abc.jpg 800 x 600) and resize it as 120 x 100, I then want to save it as c:\abc_t.jpg. Thanks Slasher
14
by: Rudy | last post by:
Hello all! I been trying to get a handle with Images. I have learned alot from the fine people here. So, I also learned that thumbnail images look terrible taken from a digital cam. I know why...
4
by: rbt | last post by:
What's a good way to resize pictures so that they work well on html pages? I have large jpg files. I want the original images to remain as they are, just resize the displayed image in the browser.
11
by: eholz1 | last post by:
Hello PHP group, I am using some php code to check the size of images, and then resize or determine new dimension for the image. GD seems quite slow. It takes about 5 seconds (plus or minus) to...
6
by: Bob Bedford | last post by:
Hi all, I've to resize uploaded images with the "imagecopyresampled" but when I've images quite large (common those days) I reach the 16mb limits of the ISP. How can I fix this ? I absolutely...
3
by: Noorain | last post by:
Sir i want to resize image. Following script working in my local server. But This coding doesn't work in php 2.6.0. please help me <form action="<?php echo $_server; ?>" method="post"...
3
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi! This discussion may help other programmers get a better idea of how to save uploaded images through a website. Why? Well currently, I save 3 versions of every uploaded image on my own...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.