PHP crop and resize images on the fly

I have a webpage that displays images that I don’t know their size in advance. I tried to use the GD functions to make the script resize and crop the images from me "Just before they are displayed .. I don't need caches", but I failed. I need a script that I can name as follows

<img src="display.php?src=blablabla&height=100&width=200" ?>

or even calculating the width and height of the css to keep the proportions and make the image by touching the box from the inside, like

<img src="blabla.jpg" style="height:<?php echo $height; ?>; width:<?php echo width; ?>" />

I do not need any caching. How can i do this?

+3
source share
4 answers

WideImage rlz! :)

Change of size:

header('Content-type: image/jpeg');

echo WideImage::load('image.jpg')->resize(200, 100)->asString('jpg', 80);
// image.jpg resized at 200x100 with 80% of quality
+7

. , CSS, .

GD, , imagecopyresampled(), , imagejpeg. :

header('Content-type: image/jpeg');
+3

TimThumb (Demo ):

"timthumb.php", (: /scripts/ ) , :

<img src="/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1" alt="">
-1
source

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


All Articles