Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8822939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:13:52+00:00 2026-06-14T06:13:52+00:00

Lets say that we have an image uploaded by the user, the upload script

  • 0

Lets say that we have an image uploaded by the user, the upload script limits the mb but not the image size (so could be any proportion, 600X200,200X350, and so…).

Im already showing this image in one part on my site using the twitter bootstrap image handler written on css, thats good for a profile picture, the problem is that now I want that image to be a cover (like facebook/twitter cover image), my site is responsive so the width of the cover is 900px or 100% if the screen resolution is less than 900px wide. The height is always fixed to 200px. So I know there is a way to control the correct image display using CSS (maybe with jquery too) but Im not a front-end dev, Im a php dev and I dont want to use server side scripts for doing this. So im looking for suggestions or pieces of codes (css, javascript) to start with, I belive that it have to be an already made solution for this, but I dont find any on google. Thanks for any advice!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:13:53+00:00Added an answer on June 14, 2026 at 6:13 am

    I would definitely not advise to use a css-only solution. Not even a client-side solution if the uploaded pictures can have any resolution. You want to use a php script to save resized versions of the uploaded images and serve those to the client. Either as a block’s background-image and use css (not cross browser) or as an img tag and use js to resize.

    css:

    .myselector{
        background-size: cover;
    } 
    

    or js (jquery):

    $(function(){
        var containers = $('.myselector'), w = $(window);
        function onResize(){
            //resize code
            containers.each(function(){
                var $this = $(this),
                    w = $this.width(),
                    h = $this.height(),
                    ratio = w/h,
                    $img = $('img',$this); // assuming there is only one img in each container
                $img.css({'width':'auto','height':'auto'});
                var iw = $img.width(), ih = $img.height(), iratio = iw/ih;
                if(iratio>ratio){
                    $img.css({
                        height:'100%',
                        width:'auto',
                        marginLeft: (w-iw*(h/ih))/2
                    });
                }
                else{
                    $img.css({
                        width:'100%',
                        height:'auto',,
                        marginTop: (h-ih*(w/iw))/2
                    });
                }
            });
        }
        w.bind('resize',onResize);
        //resize on each image load event
        $('img',containers).bind('load',onResize);
        onResize();
    });
    

    Here is a working fiddle : http://jsfiddle.net/kHxd2/2/

    The image’s onload listener might need tweeking to react when cached images are rendered in IE: http://css-tricks.com/snippets/jquery/fixing-load-in-ie-for-cached-images/

    Also you might want to set css rules for rare non-js browsers… (.myselector img{width:100%;})

    EDIT : container css:

    .myselector{
        width: 100%;
        max-width: 900px;
        height: 200px;
        margin: auto; /* centering */
        overflow: hidden;
    }
    

    see updated fiddle: http://jsfiddle.net/kHxd2/3/

    The best solution is to embed the image containers in a main wrapper div and apply the above css rules to that big container.

    Here is some useful code to take care of server-side resizing : http://www.9lessons.info/2009/03/upload-and-resize-image-with-php.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have an android application that shows an image of a pillow.
I am creating a webpage..as usual. But I have a problem. Lets say that
Lets say I have an image that has a DPI of 72 and a
Lets say I have an image in double that goes from range 0.0 to
Lets say that i have 2 pages: index.php and service.php index.php sends an http-post
Lets say that you have a following simple application: <form action=helloServlet method=post> Give name:<input
Lets say that i have a duration of time e.g., 10 minutes . I
Lets say that you have a business object whose current state implies that there
Lets say that I have an executable and when it is started I want
Lets say that I have only DHT (distributed hash table) implemented (in Python), and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.