tags:

views:

45

answers:

3

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?

+1  A: 

Yes there is. Look at the imageXXXX functions; the ones you are particularly interested in are imagecreate, imagecreatetruecolor, imagecreatefrompng, imagecopyresampled, imagecopyresized, and imagepng (assuming you're dealing with PNG images - there's similar load / save functions for jpeg, gif, and a few other formats).

tdammers
A: 

Have you tried PHPThumb? I used this class often and its pretty clean and lightweight. I used it here.

d2burke
A: 

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.

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);
Frxstrem
I have tried the examples in php.net for the above functions but all i get is a black (ot whatever color specified) re-sized image but not the original image re-sized. Even for your example i am getting black image resized. what am i doing wrong?
Scorpion King
ok so the problem is that i have to install the GD first and modify php.ini right?
Scorpion King
@Scorpion King: no, if the functions are working (i.e. they are defined), that means that GD is installed. But are you sure that `'myImage.jpg'` or whatever actually points to an existing JPEG file?
Frxstrem