Jump to content

Creating a website in Dreamweaver using MySQL and PHP


Hobgoblin11

Recommended Posts

Hmm, I'm still struggling a little with the images. Here is what I want to do:

 

 

 

I have my images stored in a folder, and I have the location of each image stored in a database. Now, I want to display each image on one page, resizing it at the same time. I have tried resizing it in the browser, and got that to work fine, but, on hindsight, that was resulting in the user downloading the full image, which they didn't need to do, and the resizing was crap. Instead, I want to call the image using PHP, resize it before it gets sent to the user, and then send the resized image to the user. The only tutorials I can find that relate to resizing images in PHP, are about actually creating images, which is not what I want to do.

 

 

 

So, in short, I want to call up an image from the server, by using the location in the database. I then want to use the GD library to resize it, and then print that image on the page that is sent to the user. Can this be done?

 

 

 

Thanks a lot.

99/99 Fletching, 99/99 Cooking, 96/99 Strength

Hobgoblin11.jpeg

Link to comment
Share on other sites

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

how are the arrays going?

 

 

 

yes, it is possible, though it is a very long script, which I can't type out at the moment. Your create an image tutorial might just be right, as you make a new file, define the height and width of the new image, then copy the old image into the new one. Then you get to blow up the old image :mrgreen:.

 

I'll help you as much as I can, wherever you may need it, as this is one of the tougher things to do with PHP (it's not actually as simple as the first part of my post may have lead you to believe :boohoo: ).

siggyanimatoin5dtbp3.gif

There are 10 types of people: Those who understand binary, and those who don't.

Appreciate Bacteria! It's the only form of culture some people have.

The brain's right side controls the body's left, so only lefties are in their right mind.

School!

Link to comment
Share on other sites

Lol, dam. OK, I'll have a crack at it. The main problem I have is that I don't want to create thumbnail files for each image, as, whilst doing it to resize it is fine, I also want to add text and stuff over the image later on. As the text is changeable, saving a thumbnail with the correct text overlay, etc. everytime it changes, just isn't practical!

 

 

 

I'm having trouble even loading my images at the moment though. I have found the script:

 


<?php

//header("Content-Type: image/jpeg");



$image = imagecreatefromjpeg("uploads/PEOJuCKrpe973nM0.jpg");

imagejpeg($image);

?>

 

 

 

However, this is no good as it only loads one image, you can't load different file types, as the header has already been set. As soon as you remove the header, it no longer interprets the file as an image and just gives you a load of garbage in text form. Any ideas?

 

 

 

As soon as I can load multiple images onto one page, I'm more or less sorted, as I can find several tutorials showing me how to resize and crop etc., my main difficulty at the mment is displaying multiple images on one page!!

 

 

 

Thanks for your help

99/99 Fletching, 99/99 Cooking, 96/99 Strength

Hobgoblin11.jpeg

Link to comment
Share on other sites

hehe, you're going to make me write it anyway. :twisted: :wall:

 


$type = getimagesize($image);

switch($type)

{

case 1:

imagecreatefromgif($img);

break;

case 2:

imagecreatefromjpeg($img);

break;

case 3:

imagecreatefrompng($img);

break;

}

 

:twisted: :twisted: :wall: :twisted:

 

:mrgreen:

siggyanimatoin5dtbp3.gif

There are 10 types of people: Those who understand binary, and those who don't.

Appreciate Bacteria! It's the only form of culture some people have.

The brain's right side controls the body's left, so only lefties are in their right mind.

School!

Link to comment
Share on other sites

Lol, thanks! That doesn't work though :-( I've managed to split the filetype from the filename and get a switch function working that selects which type of file the file is,

 

 

 

$image = "uploads/PEOJuCKrpe973nM0.jpg";

$type = strtolower(strstr($image, '.'));



switch($type)

{

case ".gif":

imagecreatefromgif($image);

break;

case ".jpg":

imagecreatefromjpeg($image);

break;

case ".jpeg":

imagecreatefromjpeg($image);

break;

case ".png":

imagecreatefrompng($image);

break;

} 

 

 

 

(I'll change the $image variable later), however, I don't get an image given, I don't get any output at all. The only way I can get an output is by using the following:

 

 

 

$image = "uploads/PEOJuCKrpe973nM0.jpg";

$type = strtolower(strstr($image, '.'));



switch($type)

{

case ".gif":

imagecreatefromgif($image);

$im = imagegif ($im);

break;

case ".jpg":

$im = imagecreatefromjpeg($image);

imagejpeg ($im);

break;

case ".jpeg":

$im = imagecreatefromjpeg($image);

imagejpeg ($im);

break;

case ".png":

$im = imagecreatefrompng($image);

imagepng ($im);

break;

} 

 

 

 

But then, it still doesn't recognise it as an image, just a load of garbled junk.

99/99 Fletching, 99/99 Cooking, 96/99 Strength

Hobgoblin11.jpeg

Link to comment
Share on other sites

Ah no problems, you have a nice trip? I've been away for the last week anyways, so not been doing much work on it.

 

 

 

I'm doing OK thanks, most of the functional bits of the site are now working, I still need to write a 'forgotten password' page(s), which I still need to figure out how I'm going to do that. I'll probably send an email to the user, replacing their password with a random one, and then requiring them to change it the next time they login.

 

 

 

I'm having a bit of a ball-ache with images at the moment though. If you read my last couple of posts, you'll pick up what I'm trying to do.

 

 

 

Hob

99/99 Fletching, 99/99 Cooking, 96/99 Strength

Hobgoblin11.jpeg

Link to comment
Share on other sites

it's likely my script didn't work because you didn't set it up right, it is part or a 3 page script :shock:

 

 

 

I can help you with the display multi images part though, this displays all the files in the directory, and if one isn't an image it may crash. here goes:

 


$files = scandir('/images');

foreach($files as $file)

{

print '
';

}

 

this assumes that this php file is in the same folder as the folder "images". it goes through the folder, putting each file into the array $files, then dissects $files and displays each file as an image.

 

 

 

hope this helps!

siggyanimatoin5dtbp3.gif

There are 10 types of people: Those who understand binary, and those who don't.

Appreciate Bacteria! It's the only form of culture some people have.

The brain's right side controls the body's left, so only lefties are in their right mind.

School!

Link to comment
Share on other sites

Hmm, I've already managed to display multiple images in a page by using HTML img src code (using a 'while' function), but thats not what I want to do. I want to return the image using PHP, so that I can alter it using PHP functions.

99/99 Fletching, 99/99 Cooking, 96/99 Strength

Hobgoblin11.jpeg

Link to comment
Share on other sites

use

 


imagecopyresampled($copy,$orig,0,0,0,0,$newWidth,$newHeight,$oldWidth,$oldHeight)

 

. Put that with the script that moves the images from the temp folder. ($copy is the path to the new pic made with imagecreatefromjpeg/gif/png()) This changes it on upload. Then you can either keep or delete the original. You can always just use the path to the temp folder as $orig, and not need to worry about deleting or moving the original image.

 

 

 

Hope that helps!

siggyanimatoin5dtbp3.gif

There are 10 types of people: Those who understand binary, and those who don't.

Appreciate Bacteria! It's the only form of culture some people have.

The brain's right side controls the body's left, so only lefties are in their right mind.

School!

Link to comment
Share on other sites

  • 1 month later...

Hey guys, I wasn't around for quite a while because I've just moved to Uni.

 

 

 

I had a discussion with a friend who was going to Uni to do Computer Science. He put doubts in my mind over whether PHP was the best language to use for what I want to do. In summary, I want to dynamically load a few thousand images onto a single web page. According to him, PHP would be a very slow way to do this, and I should start learning how to use Python and integrate it into my page. Is it worth doing this, or is he talking rubbish?

99/99 Fletching, 99/99 Cooking, 96/99 Strength

Hobgoblin11.jpeg

Link to comment
Share on other sites

Hey guys, I wasn't around for quite a while because I've just moved to Uni.

 

 

 

I had a discussion with a friend who was going to Uni to do Computer Science. He put doubts in my mind over whether PHP was the best language to use for what I want to do. In summary, I want to dynamically load a few thousand images onto a single web page. According to him, PHP would be a very slow way to do this, and I should start learning how to use Python and integrate it into my page. Is it worth doing this, or is he talking rubbish?

He's generally talking smack. Pyhton isn't any faster, and ultimately the speed of the rendering of the end result comes down to the client pc viewing the page.
Link to comment
Share on other sites

Hey guys, I wasn't around for quite a while because I've just moved to Uni.

 

 

 

I had a discussion with a friend who was going to Uni to do Computer Science. He put doubts in my mind over whether PHP was the best language to use for what I want to do. In summary, I want to dynamically load a few thousand images onto a single web page. According to him, PHP would be a very slow way to do this, and I should start learning how to use Python and integrate it into my page. Is it worth doing this, or is he talking rubbish?

He's generally talking smack. Pyhton isn't any faster, and ultimately the speed of the rendering of the end result comes down to the client pc viewing the page.

 

 

 

Even when the dynamic bit is done on the server-side?

99/99 Fletching, 99/99 Cooking, 96/99 Strength

Hobgoblin11.jpeg

Link to comment
Share on other sites

Yep. The actual script will execute and return a result in a very similiar speed (server load also an issue). The bottle neck is those images then being download and displayed on the client machine.

Link to comment
Share on other sites

you don't see too many people using python these days...

 

most websites use either php or cgi (asp is becoming popular, for whatever reason).

 

cgi and php are both good, though cgi isn't an integrated language, if memory serves.

 

All the languages are pretty much the same with image speed, as they are just calling the image, the words are different but the call is the same.

 

It is better to resize etc on upload rather than each time it is called, it sames quite some time. You may also want to have only some images showing at once, a few thousand takes up a lot of room, and time.

 

Dynamic bits generally are server side, unless you use javascript, which isn't good for more than basic tasks.

 

You can shrink the images when you want to show them, but again, that causes the wait.

siggyanimatoin5dtbp3.gif

There are 10 types of people: Those who understand binary, and those who don't.

Appreciate Bacteria! It's the only form of culture some people have.

The brain's right side controls the body's left, so only lefties are in their right mind.

School!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.