Image Resizing Script required - a better one...
Moderator: General Moderators
Re: Image Resizing Script required - a better one...
So you're uploading an image, which goes in one directory, and then creating multiple resized images which go in another directory? And all the resized images are in the same directory?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Image Resizing Script required - a better one...
Correct. So if you had shirt.jpg, and it was renamed on upload to 12345_shirt.jpg, that goes into /images/productphotos.
While 12345_shirt_475.jpg (and the other three) will go into /images/productphotos/small.
If I were to write this from scratch I'd put them in one, but I didn't. And won't. lol.
While 12345_shirt_475.jpg (and the other three) will go into /images/productphotos/small.
If I were to write this from scratch I'd put them in one, but I didn't. And won't. lol.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Image Resizing Script required - a better one...
So what's the criteria that determines whether they go in images/productphotos or images/pages?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Image Resizing Script required - a better one...
The $resize would be "thumbnails". Rather than Categories, Products or Wide.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Image Resizing Script required - a better one...
So resizeImage and getSrcSet are going to need to be changed since they both currently rely on hardcoded paths. However, we've got a common parameter being passed to both, so we can pass that parameter along to some getTargetDirectory function we've yet to create. That function could return an array containing the directory in which to store the original image as well as the directory in which to store the thumbnails. Starting to see how this would work?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Image Resizing Script required - a better one...
Sure. the both use actual_paths. So we need to tap into that, and feed it with getTargetDirectory, possibly with a 'default' one for the banners (images/pages).
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Image Resizing Script required - a better one...
I think that's a reasonable approach. First, notice that you've got the logic for $actualfolder in two different places. I'd start by extracting that to a function, then move on to having it return two directories instead of one. Take a crack at it and then we can look at fine tuning it together.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Image Resizing Script required - a better one...
Blimey I'm lost now.
If I take the Resize_type function within resizeimage as a template, that takes the 'case', and creates a variable.
But how I create then two variables, and use both within the upload script, based on the type of image I am upload, I'm lost.
I did figure out how to add one into that section, but not how to then store into TWO locations via a function. I don't want the answer, I want a steering... firstly with the right sort of function to create. I can see now the 'return' method. So I may be able to figure that bit out.
If I take the Resize_type function within resizeimage as a template, that takes the 'case', and creates a variable.
But how I create then two variables, and use both within the upload script, based on the type of image I am upload, I'm lost.
I did figure out how to add one into that section, but not how to then store into TWO locations via a function. I don't want the answer, I want a steering... firstly with the right sort of function to create. I can see now the 'return' method. So I may be able to figure that bit out.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Image Resizing Script required - a better one...
Show me what your functions file currently looks like and what you've added, and I'll give you a little nudge.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Image Resizing Script required - a better one...
Code: Select all
function getTargetDirectory($targetdirectory)
{
switch($targetdirectory) {
case 'thumbnails':
$folder_thumbnails= 'productphotos/small';
$folder_original= 'productphotos/';
break;
}
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Image Resizing Script required - a better one...
You do need to return something, and functions can only return one thing. But you need to return two values, and you need to know which is which. A single element containing key/value pairs....
Also, don't forget that you're going to be calling this function regardless of the value of $resize, so you need to be able to return something for all cases.
Also, don't forget that you're going to be calling this function regardless of the value of $resize, so you need to be able to return something for all cases.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Image Resizing Script required - a better one...
Am I right in any of this... or is not where you'd start at all?
ie. do I return the two values, assuming I must, since I have two file paths.
ie. do I return the two values, assuming I must, since I have two file paths.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Image Resizing Script required - a better one...
Code: Select all
$paths = array(
'fullsize' => '/path/to/full/images',
'thumbnails' => '/path/to/thumbnails',
);-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Image Resizing Script required - a better one...
Ok. So before I return $paths(), do I need to add in a default there for the images/pages?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Image Resizing Script required - a better one...
I would recommend it, yes. If you don't, what happens when $targetdirectory is not 'thumbnails'?