Resize images by passing the values through the url

2

In my program downloads site, there are images of various sizes, for example: for each program has a thumbnail, a large image and the screenshots.

I just want to make the images all of the same size and by the url pass the size I want from the image. Something like: uploads/imagens/imagen-teste.jpg?w=500&h=500 . If I want the same image in another size, I would only pass the value through the url, thus: uploads/imagens/imagen-teste.jpg?w=100&h=100 .

How can I do this? Or is there a plugin that does this?

    
asked by anonymous 18.07.2017 / 16:06

1 answer

3

Hello.

To get through the URL, you would need to request a get by passing width and height.

You can do this easily with PHP.

<?php

//Parametros obtidos via Get
$width = $_GET('WIDTH');
$height = $_GET('HEIGHT');

//URL da imagem
$url = 'img/foto.jpg';

//pega a imagem para redimensionar com base na URL
$image = imagecreatefromjpeg($url);

//pega a largura e altura original da imagem
$orig_width = imagesx($image);
$orig_height = imagesy($image);

//Gera a nova imagem e redimensiona com base nos valores passados
$new_image = imagecreatetruecolor($width, $height);
imagecopyresized($new_image, $image, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height);

//Exibe a imagem
imagejpeg($new_image);
?>

for more information: link

    
18.07.2017 / 18:02