Joseph  Norton

Joseph Norton


Resize slider with different sized images

I have a mobile first slider with 3 types of images: tall, horizontally long and square. I want the horizontally long image determine the size of slider and then scale and center other ones to fit it's size. Using width:100%; height:auto; in my CSS code so images will be loaded with same width(100%) and different heights. Then using JS I want to get height of the image which has max width/height ratio and use it as the height of all images. And in the end using width:auto; height:100%; for images so all of them will fit the height. Here is the code I used to achieve this:

every slide has the following HTML:

<div class="img">
      <img src="" alt="">

CSS code:

     position: relative;
     vertical-align: middle;

.img img{
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;

JS code:

        $(“.img img”).width = “100%”;
$(“.img img”).height = “auto”;;
var img_h , Imgs_heights=[] , ratio=[];
slider.item.find(“.img img”).each(function(){
img_h = Math.max.apply(Math,ratio);
var i = r.indexOf(img_h );
$(“.img img”).css(“height”, “100%”);
$(“.img img”).css(“width”, “auto”);

Everything works just fine but I have problem when I resize the window. In resizing the height of images does not change and keeps the height calculated before. And I need to refresh page to see the result I want. How can I get the height to change? I added the two first lines in JS to force it take width:100%; height:auto; again in resized window but it does not work.

I will appreciate any help.

#javascript #css #jquery #image

What is GEEK

Buddha Community

If I’m understanding you correctly, can you simply use the Javascript window.resize event to recalculate the image sizes?

From Mozilla

The resize event fires when the document view (window) has been resized.
Your code might become something like:

function resizeImages(){
   $(".img img").width = "100%";
   $(".img img").height = "auto";
   var img_h , Imgs_heights=[] , ratio=[];
   slider.item.find(".img img").each(function(){
   img_h = Math.max.apply(Math,ratio);
   var i = r.indexOf(img_h );
   $(".img img").css("height", "100%");
   $(".img img").css("width", "auto");

window.onload = function(){

window.onresize  = function(){

I am Developer


How to Compress Image Size In Codeigniter 4

Codeigniter compress image size. In this tutorial, you will learn how to upload and compress image size in codeigniter app.

This tutorial will guide you step by step on how to compress image size and upload in codeigniter app. And you can easily compress any image type like png, jpg, jpeg, gif etc.

How to Compress Image Size In CodeIgniter

Follow the following steps and you can easily compress image size in codeigniter app:

  • Download Codeigniter Latest
  • Basic Configurations
  • Create Database With Table
  • Setup Database Credentials
  • Create Controller
  • Create Views
  • Start Development server

#codeigniter compress image size #codeigniter compress image size example #codeigniter 4 compress image size #image resize in codeigniter

I am Developer


Crop and Resize Image Before Upload In Laravel Using with jQuery Copper JS

Crop and resize image size before upload in laravel using jquery copper js. In this post, i will show you how to crop and resize image size in laravel using jQuery copper js in laravel.

This laravel crop image before upload using cropper js looks like:

laravel crop image before upload

Laravel Crop Image Before Uploading using Cropper js Tutorial

Laravel crop image before upload tutorial, follow the following steps and learn how to use cropper js to crop image before uploading in laravel app:

  • Step 1: Install New Laravel App
  • Step 2: Add Database Details
  • Step 3: Create Migration & Model
  • Step 4: Add Route
  • Step 5: Create Controller By Artisan
  • Step 6: Create Blade View
  • Step 7: Make Upload Directory
  • Step 8: Start Development Server


Live Demo Laravel Crop image Before Upload.

#laravel crop image before upload, #laravel crop and resize image using cropper.js #ajax image upload and crop with jquery and laravel #crop and upload image ajax jquery laravel #crop image while uploading with jquery laravel #image crop and upload using jquery with laravel ajax

I am Developer


Laravel 7/6 Image Validation

In this image validation in laravel 7/6, i will share with you how validate image and image file mime type like like jpeg, png, bmp, gif, svg, or webp before uploading image into database and server folder in laravel app.

#laravel image validation #image validation in laravel 7 #laravel image size validation #laravel image upload #laravel image validation max #laravel 6 image validation

I am Developer


Node JS Resize Image Before Upload Example

Resize image before upload using multer, sharp with node js and express js. In this node js tutorial, you will learn how to resize image before upload using multer, sharp with node js and express js.

Image upload is the basic requirement of any application. So this example will guide you step by step on how to resize image before upload using multer in node js. And you can understand a concept of node js compress image before upload.

Node Express Resize Image Before Upload Tutorial Example

Step 1 - Create Node JS App

Step 2 - Install Express and Multer Dependencies

Step 3 - Import Dependencies in Server.js File

Step 4 - Create Server.js File

Step 5 - Create Form

Step 6 - Run Development Server

#how to upload multiple image in node js #resize image in nodejs #image processing in node js #node js image upload resize

I am Developer


Laravel 7/6 Intervention Image Resize

laravel intervention image upload and resize tutorial. Here, i will show you how to resize image before upload using intervention image package in laravel.

Laravel Intervention Resize Image Upload and Save to Storage

Use the following steps and image upload in laravel using intervention package with save to storage:

  1. Install Laravel App
  2. Setup Database
  3. Install Image Intervention Package
  4. Generate Image migration file and model
  5. Make Upload And Resize Image Route
  6. Create Upload And Resize Image Controller & Methods
  7. Create Blade View
  8. Make Folder
  9. Start Development Server

#laravel intervention image resize #laravel intervention image upload #laravel intervention image save to storage #laravel intervention image thumbnail #laravel intervention image compression