Image Resizing Script required - a better one...
Moderator: General Moderators
-
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...
So how do I set a default?
I guess this function is pretty small. Just a way of saying if this is "thumbnails" use these directories... else... use this one.
I know how to do it in PHP normally:
if ($target == "thumbnails")
{
$path == "/thisone/";
}
else
{
$path == "differentone";
}
But not in a function I don't know.
I guess this function is pretty small. Just a way of saying if this is "thumbnails" use these directories... else... use this one.
I know how to do it in PHP normally:
if ($target == "thumbnails")
{
$path == "/thisone/";
}
else
{
$path == "differentone";
}
But not in a function I don't know.
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...
It's nearly the same.simonmlewis wrote:So how do I set a default?
I guess this function is pretty small. Just a way of saying if this is "thumbnails" use these directories... else... use this one.
I know how to do it in PHP normally:
if ($target == "thumbnails")
{
$path == "/thisone/";
}
else
{
$path == "differentone";
}
But not in a function I don't know.
Code: Select all
function getPath($target)
{
if ($target == "thumbnails") {
$path = "/thisone/";
} else {
$path = "differentone";
}
return $path;
}Re: Image Resizing Script required - a better one...
Alternately, without the else:
Code: Select all
function getPath($target)
{
if ($target == "thumbnails") {
return "/thisone/";
}
return "differentone";
}-
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 getPath($target)
{
if ($target == "thumbnails")
{
$paths = array(
'fullsize' => '/images/productphotos',
'thumbnails' => '/images/productphotos/small',
);
}
else
{
$paths = '/images/pages';
}
return $path;
}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...
That could work, but it could also be problematic. How are you planning on using this?
-
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...
I guess the $paths would be an array, and would need to be 'opened' if the upload is a thumbnail.
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...
Could you not return a full path and a thumbnails path in all instances?simonmlewis wrote:I guess the $paths would be an array, and would need to be 'opened' if the upload is a thumbnail.
-
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...
Sorry..? /images/pages doesn't have a thumbnails path.
Or do you mean to do it, even if the pages/ thumbnails path goes nowhere..?
Or do you mean to do it, even if the pages/ thumbnails path goes nowhere..?
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...
But it does go somewhere. The thumbnails get saved somewhere, don't they?
-
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...
I said this earlier: product photos...:
originals go in "images/productphotos"
Resized ones go in "images/productphotos/small".
Banners like on the homepage, ALL go in /images/pages. No additional "thumbnails" for those. they are resized as you know, but they all go to the same place.
originals go in "images/productphotos"
Resized ones go in "images/productphotos/small".
Banners like on the homepage, ALL go in /images/pages. No additional "thumbnails" for those. they are resized as you know, but they all go to the same place.
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...
Ah, but who said anything about additional?simonmlewis wrote:I said this earlier: product photos...:
originals go in "images/productphotos"
Resized ones go in "images/productphotos/small".
Banners like on the homepage, ALL go in /images/pages. No additional "thumbnails" for those. they are resized as you know, but they all go to the same place.
Code: Select all
function getPath($target)
{
$paths = array(
'fullsize' => '/images/pages',
'thumbnail' => '/images/pages',
);
if ($target === 'thumbnails') {
$paths['fullsize'] = '/images/productphotos';
$paths['thumbnail'] = '/images/productphotos/small';
}
return $paths;
}-
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...
Yes that is what I was hinting at myself! $thumbnail to be erroneous almost, but I suppose since it is in an array, it forces them all the to same place.
So you have there the default for $paths. And if the target is thumbnails, it set the arrange for paths.
Ok got that.
So you have there the default for $paths. And if the target is thumbnails, it set the arrange for paths.
Ok got that.
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...
The advantage to this approach is you don't need to check later if it's an array or just a single path. You know you're getting an array back so you can set up functions that rely on this accordingly. It also gives you the flexibility to make changes down the road in only a single spot.simonmlewis wrote:Yes that is what I was hinting at myself! $thumbnail to be erroneous almost, but I suppose since it is in an array, it forces them all the to same place.
So you have there the default for $paths. And if the target is thumbnails, it set the arrange for paths.
Ok got that.
-
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...
Gotcha. I was trying to lead toward that, but not in the right wy, as my version didn't have the second bit in an array.
So now it knows it's "thumbnails". How am I telling it that? Should the 'resize' not be in the function, to relay it from the form?
So now it knows it's "thumbnails". How am I telling it that? Should the 'resize' not be in the function, to relay it from the form?
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're passing $resize into your resizeImage function, and you're calling this function from inside resizeImage. Just pass the parameter along.simonmlewis wrote:So now it knows it's "thumbnails". How am I telling it that? Should the 'resize' not be in the function, to relay it from the form?
Code: Select all
// Takes input from a form post and saves original image plus all required resizes
function resizeImage($path_to_file, $file_name, $resize_type)
{
$imagine = new Imagine\Gd\Imagine();
$target_directory = dirname(__DIR__) . getPath($resize_type);
$pathinfo = pathinfo($file_name);
// etc...
}