How to make all images the same size

Asked

Viewed 1,599 times

1

  • You can force the width and height of the images in css. It’s not a good practice, but it works...

  • What should I do?

  • Same width, same height, or will you cut to be in the same shape? If you cut, you have to choose the alignment manually.

  • this is for an ad site what seems most viable for this situation?

2 answers

0

To change the size of ALL page images at once, try this in your css:

img {
width: 800px!important;
height: 600px!important;
}

Change the 800 and 600 to the desired values. You can also change the size of all the images that are inside a div, for example. The code would look like this:

div#imagens img {
width: 800px!important;
height: 600px!important;
}

And your div would need the id "images", as in the code

<div id="imagens">
<img src="/imagem1.png />
<img src="/imagem2.png />
</div>

0


CSS will solve your problem, but from what I saw on your site your image is 3000px wide, the best would be to decrease the size of it on the same server, saw.

I use this code below to do this function, in which $max_x is the final width of the image and $max_y its height. Note that $vDestino1 must be the original image (the file going up) and $vDestino2 is the way where the small image will be saved.

                $max_x = 150;
                $max_y = 150;


                list($width, $height) = getimagesize($vDestino1);
                $original_x = $width;
                $original_y = $height;
                if($original_x > $original_y){
                    $porcentagem = (100 * $max_x) / $original_x;
                }else{
                    $porcentagem = (100 * $max_y) / $original_y;
                }
                $tamanho_x = $original_x * ($porcentagem / 100);
                $tamanho_y = $original_y * ($porcentagem / 100);
                $image_p = imagecreatetruecolor($tamanho_x, $tamanho_y);
                switch (strtolower(substr($vDestino1, -3))){
                    case "jpg":

                    $image   = imagecreatefromjpeg($vDestino1);
                    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $tamanho_x, $tamanho_y, $width, $height);
                    imagejpeg($image_p, $vDestino2, 90);
                    break;

                    case "gif":

                    $image_p = imagecreatetruecolor($tamanho_x, $tamanho_y);
                    imagealphablending($image_p, false);
                    imagesavealpha($image_p,true);
                    $transparent = imagecolorallocatealpha($image_p, 255, 255, 255, 127);
                    imagefilledrectangle($image_p, 0, 0, $tamanho_x, $tamanho_y, $transparent);

                    $image   = imagecreatefromgif($vDestino1);
                    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $tamanho_x, $tamanho_y, $width, $height);
                    imagegif($image_p, $vDestino2);
                    break;

                    case "png":

                    $image_p = imagecreatetruecolor($tamanho_x, $tamanho_y);
                    imagealphablending($image_p, false);
                    imagesavealpha($image_p,true);
                    $transparent = imagecolorallocatealpha($image_p, 255, 255, 255, 127);
                    imagefilledrectangle($image_p, 0, 0, $tamanho_x, $tamanho_y, $transparent);

                    $image   = imagecreatefrompng($vDestino1);
                    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $tamanho_x, $tamanho_y, $width, $height);
                    imagepng($image_p, $vDestino2);
                    break;

                }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.