使用php动态调整图片大小 [英] dynamic image resize using php

查看:73
本文介绍了使用php动态调整图片大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像,该图像将用作背景图像,并且将从数据库中提取其他一些我想在该图像中显示的图像.因此,如果我只拉一张图像,我希望背景图像的底部在第一张图像后关闭,如果有多个图像,那么我希望在显示这些图像后将其关闭.不使用单独的图像的问题是图像的边框具有设计格式,我无法单独显示它们.

I have an image which i am going to be using as a background image and will be pulling some other images from the database that i want to show within this image. So if i am pulling only 1 image, i want the bottom part of the background image to close after the first image, if there are multiple images then i want it close after those images are shown. The problem with not using separate images is that the borders of the images have a design format and i cannot show them separately.

看看此图像.左右边框的设计格式比仅裁剪并使用它们要复杂得多.有什么动态图像调整大小的建议吗?

Take a look at this image . The design format of the right and left borders are more complicated than that to just crop them and use them. Any suggestions if there is any dynamic image resizing thing?

推荐答案

您应该尝试使用 GD扩展对于PHP,请特别关注 imagecopyresize() .这使您可以非常轻松地进行一些基本的图像转换和操作.

You should try using the GD extension for PHP, especially have a look at imagecopyresized(). This allows you to do some basic image conversion and manipulation very easily.

一个带有两个GET参数的基本示例,调整我们的 myImage.jpg 图像大小并将其输出为PNG图像:

A basic example that takes two GET parameters, resizes our myImage.jpg image and outputs it as a PNG image:

<?php
// width and height
$w = $_GET['w'];
$h = $_GET['h'];
// load image
$image = imagecreatefromjpeg('myImage.jpg');
// create a new image resource for storing the resized image
$resized = imagecreatetruecolor($w, $h);
// copy the image
imagecopyresized($resized, $image, 0, 0, 0, 0, $w, $h, imagesx($image), imagesy($image));
// output the image as PNG
header('Content-type: image/png');
imagepng($resized);

这篇关于使用php动态调整图片大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆