How to pick up only the images vertically?

Asked

Viewed 153 times

1

My question is the following: Is there any way I can take Javascript only the images that are vertical and change them? I have several images on the site, many of them are horizontal and some vertical. I want to take only the vertical ones and change their size.

This is my code:

<?php               
        require_once("classe/conexao.class.php");
        $c = new Conexao();
        $c->Conecta();
        $c->SelecionaBase();

        $titulo = $_GET['ti'];
        $sql = mysql_query("SELECT * FROM ultimos_eventos WHERE nome_fotos = '$titulo'");
        while($aux = mysql_fetch_assoc($sql)){

                $nome = $aux['nome_fotos'];
                $imagem = $aux['img'];
                $id = $aux['id'];
                $_SESSION['id'] = $id;

                print"  
                    <div class=\"row1\">
                    <div class=\"portfolio-item col-md-3 col-sm-6\">
                        <div class=\"portfolio-thumb\">
                            <img src=\"images/$imagem\" alt=\"$nome\">
                            <div class=\"portfolio-overlay\">
                                <h3>$titulo</h3>
                                <a href=\"images/$imagem\" data-rel=\"lightbox\" class=\"expand\">
                                    <i class=\"fa fa-search\"></i>
                                </a>
                            </div> <!-- /.portfolio-overlay -->
                        </div> <!-- /.portfolio-thumb -->
                    </div> <!-- /.portfolio-item -->
                </div>";
        }
        mysql_close();
 ?>

How do I implement this in my code?

1 answer

1

You can compare the image dimensions, so if the width is less than the height, you can consider that the image is vertical, right? Example:

var imgs = document.getElementsByTagName("img");

for (var i = 0; i < imgs.length; i++)
{
    if (imgs[i].width < imgs[i].height)
    {
        alert(imgs[i].title);
    }
}

Fiddle

  • type i do this script I want to give the size only img in vertical change only it as q i do it?

  • @carlosgoncalves you just explained that you want to select the images but did not say what you want to do with them. So how to help in this. Inside the loop you already have the image, just manipulate it.

  • i want to pick up only the verticals I’m doing inside the loop you send and it always picks tds msm I specify that I want only the verticals

  • @carlosgoncalves use console.log(imgs[i].width) inside the if inside the loop to see if JS is reading the attribute correctly. Know how to debug with dev tools ?

  • face in javascript manjo nd manjo nd msm to scratch Aki intao a Resp for your Perg and not

  • @carlosgoncalves the command console.log printa value in your console, which is in the Dev Tool which in the most common browsers opens with the F12 key. In Dev Tools you will have several tabs, look for Console and its value will be there imprinted.

Show 1 more comment

Browser other questions tagged

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