Page 26 of 37
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 12:32 pm
by Celauran
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?
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 12:35 pm
by simonmlewis
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.
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 12:38 pm
by Celauran
So what's the criteria that determines whether they go in images/productphotos or images/pages?
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 12:41 pm
by simonmlewis
The $resize would be "thumbnails". Rather than Categories, Products or Wide.
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 12:44 pm
by Celauran
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?
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 12:48 pm
by simonmlewis
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).
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 12:53 pm
by Celauran
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.
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 1:00 pm
by simonmlewis
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.
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 1:02 pm
by Celauran
Show me what your functions file currently looks like and what you've added, and I'll give you a little nudge.
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 1:08 pm
by simonmlewis
Code: Select all
function getTargetDirectory($targetdirectory)
{
switch($targetdirectory) {
case 'thumbnails':
$folder_thumbnails= 'productphotos/small';
$folder_original= 'productphotos/';
break;
}
I really don't know where to go from here. I know I need to 'return' something, so it knows the default location, or the one(s) I have set.
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 1:12 pm
by Celauran
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.
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 1:13 pm
by simonmlewis
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.
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 1:15 pm
by Celauran
Code: Select all
$paths = array(
'fullsize' => '/path/to/full/images',
'thumbnails' => '/path/to/thumbnails',
);
Functions can only return one thing. $paths is one thing.
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 1:19 pm
by simonmlewis
Ok. So before I return $paths(), do I need to add in a default there for the images/pages?
Re: Image Resizing Script required - a better one...
Posted: Mon Mar 13, 2017 1:21 pm
by Celauran
I would recommend it, yes. If you don't, what happens when $targetdirectory is not 'thumbnails'?