/    Sign up×
Community /Pin to ProfileBookmark

Changing a pics size according to resolution

I know I asked this awhile ago but I can’t find the page I used it in now… nor can I find the thread I stated the question in…. I need a bit of script that will change the size of a picture according to resolution

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliMar 19.2004 — something along these lines may work for you

[url=http://www.webapplikations.com/pages/html_js/image_examples/ResizeImageOnResize.html]Resource Here[/url]
Copy linkTweet thisAlerts:
@sorrowfulkillerauthorMar 20.2004 — [i]Originally posted by Khalid Ali [/i]

[B]something along these lines may work for you

[url=http://www.webapplikations.com/pages/html_js/image_examples/ResizeImageOnResize.html]Resource Here[/url] [/B]
[/QUOTE]

Doesn't help.. I need something that works with the screen resolution.. not the window resolution
Copy linkTweet thisAlerts:
@steelersfan88Mar 20.2004 — [code=php]<script type="text/javascript">

var screenH = screen.height
var screenW = screen.width

var newW = screenW / 5
var newH = screenH / 5

document.write('<img src="mypic.jpg" height='+ newH +' width='+ newW +' alt="my pic" id="pic">')

</script>[/code]
This will write an image height and width 1/5 size of max screen height and width (which are often a tad more than actual resolution)

Of course, if the user changes resolution while viewing your page, there will be no change in size until page refreshed.
Copy linkTweet thisAlerts:
@sorrowfulkillerauthorMar 20.2004 — [i]Originally posted by steelersfan88 [/i]

[B][code=php]<script type="text/javascript">

var screenH = screen.height
var screenW = screen.width

var newW = screenW / 5
var newH = screenH / 5

document.write('<img src="mypic.jpg" height='+ newH +' width='+ newW +' alt="my pic" id="pic">')

</script>[/code]
This will write an image height and width 1/5 size of max screen height and width (which are often a tad more than actual resolution)

Of course, if the user changes resolution while viewing your page, there will be no change in size until page refreshed. [/B][/QUOTE]

I need it so I can specify how big the picture while be at a certain resolution... >_<
Copy linkTweet thisAlerts:
@steelersfan88Mar 20.2004 — something like an array of screen heights and widths? Like:[code=php]<script type="text/javascript">

var screenW = screen.width
var screenH = screen.height

var toWidth = -1
var toHeight = -1

var maxH = 600 // height/width if resolution is greater
var maxW = 600 // than those given in the array

/**************************************

* Change all height and widths here
* The screen is the possible height/width
of the screen
* The img is the height/width of the
image at that or a smaller resolution
* Keep all resolutions in ascending
order, smaller at top!

**************************************/

var heights = new Array
heights[0] = {screen:"600",img:"250"}
heights[1] = {screen:"768",img:"350"}
heights[2] = {screen:"864",img:"500"}

var widths = new Array
widths[0] = {screen:"800",img:"250"}
widths[1] = {screen:"1024",img:"350"}
widths[2] = {screen:"1152",img:"500"}

/*** DO NOT EDIT BELOW THIS LINE ***/

for(var i=0;i<widths.length;i++) {
if(screenW <= widths[i].screen) {
toWidth = i
break;
}
}

for(var i=0;i<heights.length;i++) {
if(screenH <= heights[i].screen) {
toHeight = i
break;
}
}

var picH = ""
var picW = ""

if(toHeight < 0) {
// picture bigger than given resolutions
picH = maxH
}
else {
picH = heights[toHeight].img
}

if(toWidth < 0) {
// picture bigger than given resolutions
picW = maxW
}
else {
picW = heights[toWidth].img
}

/*** DO NOT EDIT ABOVE THIS LINE ***/

// Change the src of the image and alt text only
document.write("<img src='myPic.jpg' alt='my pic' height="+ picH +" width="+ picW +">")

</script>[/PhP]The script can probably be condensed, i tried to comment somewhat and put a little bit of spacing to improve legibility.
Copy linkTweet thisAlerts:
@Khalid_AliMar 20.2004 — [i]Originally posted by sorrowfulkiller [/i]

[B]Doesn't help.. [/B][/QUOTE]

in that I ma sure you are one of those who will not want to think at all and I am sure even what steelers posted the second time, that won't work for you...

The purpose here is usally to guide a member in a right direction,not to give 100 % customised solution for your problem( though I know that we all,volunteers here, if we have time,tend to do that).

Anyways I hope this latest by steelers help you.
Copy linkTweet thisAlerts:
@sorrowfulkillerauthorMar 20.2004 — [i]Originally posted by steelersfan88 [/i]

[B]something like an array of screen heights and widths? Like:[code=php]<script type="text/javascript">

var screenW = screen.width
var screenH = screen.height

var toWidth = -1
var toHeight = -1

var maxH = 600 // height/width if resolution is greater
var maxW = 600 // than those given in the array

/**************************************

* Change all height and widths here
* The screen is the possible height/width
of the screen
* The img is the height/width of the
image at that or a smaller resolution
* Keep all resolutions in ascending
order, smaller at top!

**************************************/

var heights = new Array
heights[0] = {screen:"600",img:"250"}
heights[1] = {screen:"768",img:"350"}
heights[2] = {screen:"864",img:"500"}

var widths = new Array
widths[0] = {screen:"800",img:"250"}
widths[1] = {screen:"1024",img:"350"}
widths[2] = {screen:"1152",img:"500"}

/*** DO NOT EDIT BELOW THIS LINE ***/

for(var i=0;i<widths.length;i++) {
if(screenW <= widths[i].screen) {
toWidth = i
break;
}
}

for(var i=0;i<heights.length;i++) {
if(screenH <= heights[i].screen) {
toHeight = i
break;
}
}

var picH = ""
var picW = ""

if(toHeight < 0) {
// picture bigger than given resolutions
picH = maxH
}
else {
picH = heights[toHeight].img
}

if(toWidth < 0) {
// picture bigger than given resolutions
picW = maxW
}
else {
picW = heights[toWidth].img
}

/*** DO NOT EDIT ABOVE THIS LINE ***/

// Change the src of the image and alt text only
document.write("<img src='myPic.jpg' alt='my pic' height="+ picH +" width="+ picW +">")

</script>[/PhP]The script can probably be condensed, i tried to comment somewhat and put a little bit of spacing to improve legibility. [/B][/QUOTE]
Exactly what I was looking for, thanks...

btw Khalid Ali, I'm fairly new to javascript and I don't really know how I would've done something like this...
Copy linkTweet thisAlerts:
@Khalid_AliMar 20.2004 — [i]Originally posted by sorrowfulkiller [/i]

[B]

btw Khalid Ali, I'm fairly new to javascript [/B]
[/QUOTE]

fair enough,pardon my little rant above,its that soe times there are people who will not want to learn rather try to get the complete solution..Glad you got your help here..:-)
Copy linkTweet thisAlerts:
@sorrowfulkillerauthorMar 20.2004 — [i]Originally posted by Khalid Ali [/i]

[B]fair enough,pardon my little rant above,its that soe times there are people who will not want to learn rather try to get the complete solution..Glad you got your help here..:-) [/B][/QUOTE]

I know exactly what you mean... They don't want to learn it for themselves so they just ask people how to do it... it bugs the hell out of me... >_<
Copy linkTweet thisAlerts:
@steelersfan88Mar 20.2004 — glad that we can all make up, and that you have received what you needed, and to help out!
×

Success!

Help @sorrowfulkiller spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...