bla blah" in the signature field If the image ...">

Resize Images

I am working on an application in PHP. I have a " <img src='randomimage.png'><br>bla blah" in the signature field

If the image is larger than the field, it stretches my tables and looks bad. Is there a way to resize an image if it is too large?

Sorry for my poor English and thank you for reading

Edit: The fact is that this is not just an image. This image and text are "big text".

Regards, Tom

+3
source share
8 answers

PHP ...

gdlibrary (. PHP/GD - ), , PHP.

JQuery/JavaScript

, ( ). maxSide: http://css-tricks.com/maxside-jquery-plugin-and-how-to/

CSS...

- css:

<img src="randomimage.png" />

<div class="sigBox"><img src="randomimage.png" /></div>

CSS:

div.sigBox { overflow:hidden; width:50px; height:50px; }

, .

+4

, . , HTML width img.

. , , GD Library.

+3
<img src="/img/foo.png" height="100" width="100" />

. , HTML ( , "" ).

, PHP GD: http://us.php.net/manual/en/ref.image.php

0

, , div overflow: hidden, CSS. , , 600x300 , - 400x90. , .

0

JoshL John T, php, , . php script, , , , .

You end up using something like this in your HTML code

<img src="img.php?file=foobar.jpg">
0
source

Using Javascript:

function changeSize(imageOrTextId, tableId)
{
    if (document.getElementById(imageOrTextId).width > document.getElementById(tableId).width)
    {
        document.getElementById(imageOrTextId).width = document.getElementById(tableId).width;
    }
}

HTML example:

<body onload="changeSize('image1', 'table1')">
    <table id="table1" width="400" height="400">
        <img src="randomimage.png" id="image1" />
    </table>
</body>

EDIT: Looks like John T also posted this way of doing this ... Sorry, I did not notice it before posting.

0
source

Css usage

<img src="randomimage.png" style="max-width:100px;max-height:100px;" />

This works in all browsers I tested.

0
source
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
             <html xmlns="http://www.w3.org/1999/xhtml">
              <head>
             <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
        </head>

       <body>
        <?php
      $thumb_width = 100;
      $thumb_height = 100;
        $full = imagecreatefromjpeg('sample.jpg');
        $width = imagesx($full);
     $height = imagesy($full);

      if($width < $height) {
$divisor = $width / $thumb_width;
       } 
       else {
$divisor = $height / $thumb_height;
     }

    $new_width= ceil($width / $divisor);
  $new_height = ceil($height / $divisor);

  //get center point
  $thumbx = floor(($new_width - $thumb_width) / 2);
  $thumby = floor(($new_height - $thumb_height)/2);

 $new_image = imagecreatetruecolor($new_width, $new_height);
  $new_image_fixed = imagecreatetruecolor($thumb_width, $thumb_height);

   imagecopyresized($new_image, $full, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

   imagecopyresized($new_image_fixed, $new_image, 0, 0, $thumbx, $thumby, $thumb_width,                                      $thumb_height, $thumb_width, $thumb_height);

     imagejpeg($new_image, "new_sample.jpg", 100);
    imagejpeg($new_image_fixed, "new_sample_fixed.jpg", 100);
     ?>
     </body>
      </html>
0
source

Source: https://habr.com/ru/post/1715460/


All Articles