Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-28-2011, 01:52 PM   PM User | #1
ifuseeknikcky
New to the CF scene

 
Join Date: Jul 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ifuseeknikcky is an unknown quantity at this point
Question Resize pictures with Javascript

Hi, I'm currently creating a blog with Blogger and I'm facing an issue with pictures sizes. My skills ? I'm a newbie...

Blog Address: http://www.blogmpocom.com/
Browser(s) Name/Version (ex: Firefox 4, Internet Explorer 8): Firefox 4, Chrome


OK, so I want the picture in the thumbnail to be CROPPED and not SCALED DOWN/RESIZED automatically, how do I do ? The thumbnail is 274px (width) by 101px (height), the picture in the thumbnail has to be 274px by 101px too but it must not be distorted.

Here is the Javascript code which needs to be worked on:

function createSummaryAndThumb(pID){
var div = document.getElementById(pID);
var imgtag = "";
var img = div.getElementsByTagName("img");
var summ = summary_noimg;
if(img.length>=1) {
imgtag = '<span style="text-align:center; margin-bottom:10px;"><img src="'+img[0].src+'" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px"/></span>';
summ = summary_img;
}

....... (these dots are NOT in the code, they just separate the 2 Javascript bits)

function createSummaryAndThumbF(pID){
var div = document.getElementById(pID);
var imgtag = "";
var img = div.getElementsByTagName("img");
var summ = summaryf_noimg;
if(img.length>=1) {
if(thumbnail_modef == "float") {
imgtag = '<span style="float:left;margin:0px 10px 10px 0;"><img src="'+img[0].src+'" width="'+img_thumbf_width+'px" height="'+img_thumbf_height+'px"/></span>';
summ = summaryf_img;
} else {
imgtag = '<div style="padding:0px" text-align="center"><img src="'+img[0].src+'" width="'+img_thumbf_width+'px" height="'+img_thumbf_height+'px"/></div>';
summ = summaryf_img;
}
}


I tried several tricks but the picture in the thumbnail is either still distorted or the thumbnail and the picture are the same size...
Any help is highly apreciated, thanks in advance !
ifuseeknikcky is offline   Reply With Quote
Old 07-29-2011, 03:56 PM   PM User | #2
nomanic
Regular Coder

 
nomanic's Avatar
 
Join Date: Feb 2009
Location: United Kingdom
Posts: 252
Thanks: 9
Thanked 33 Times in 33 Posts
nomanic is an unknown quantity at this point
make a div 274px by 101px with overflow hidden, and shove the image tag with no width or height restrictions inside it, it will crop the image to your desired size.

try this -

Code:
function createSummaryAndThumb(pID){
var div = document.getElementById(pID);
var imgtag = "";
var img = div.getElementsByTagName("img");
var summ = summary_noimg;
if(img.length>=1) { 
imgtag = '<span style="text-align:center; margin-bottom:10px;width:'+img_thumbf_width+'px;height'+img_thumbf_height+'px;overflow:hidden;"><img src="'+img[0].src+'"/></span>';
summ = summary_img;
}
...
function createSummaryAndThumbF(pID){
var div = document.getElementById(pID);
var imgtag = "";
var img = div.getElementsByTagName("img");
var summ = summaryf_noimg;
if(img.length>=1) { 
if(thumbnail_modef == "float") {
imgtag = '<span style="float:left;margin:0px 10px 10px 0;width:'+img_thumbf_width+'px;height'+img_thumbf_height+'px;overflow:hidden;"><img src="'+img[0].src+'"/></span>';
summ = summaryf_img;
} else {
imgtag = '<div text-align="center" style="padding:0px;width:'+img_thumbf_width+'px;height'+img_thumbf_height+'px;overflow:hidden;"><img src="'+img[0].src+'"/></div>';
summ = summaryf_img;
}
}
not sure about the spans, div should be fine

Last edited by nomanic; 07-29-2011 at 04:03 PM.. Reason: added code
nomanic is offline   Reply With Quote
Old 08-02-2011, 05:51 PM   PM User | #3
ifuseeknikcky
New to the CF scene

 
Join Date: Jul 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ifuseeknikcky is an unknown quantity at this point
Thank you for your answer, Nomanic ! However, how do I make a div 274px by 101px with overflow hidden ?

I replaced the code I currently have in my Blogger template with the one you provided and it doesn't work.

Sorry for being heavy, i'm clueless
ifuseeknikcky is offline   Reply With Quote
Reply

Bookmarks

Tags
blogger, javascript, picture, size

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:39 AM.


Advertisement
Log in to turn off these ads.