PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Mar 23, 2017 9:10 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 539 posts ]  Go to page Previous  1 ... 32, 33, 34, 35, 36  Next
Author Message
PostPosted: Wed Mar 15, 2017 7:36 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4138
Location: United Kingdom
Mmmm but you can see what I am trying to do. As I said a bit lost.
Syntax: [ Download ] [ Hide ]
if ($resize_type == "thumbnails" || $resize_type == "stockbanner")
{
  if (file_exists($thumbnail_directory . DIRECTORY_SEPARATOR . $fullname))
  {
    $srcset[] = "{$images_path}/{$fullname} {$size}w";
  }
  else
  {
    resizeSingleImage($filename, $size, $width, $resize_type);
    $srcset[] = "{$images_path}/{$fullname} {$size}w";
  }
}
else
  {
    if (file_exists($thumbnail_directory . DIRECTORY_SEPARATOR . $fullname))
  {
    $srcset[] = "{$images_path}/{$filename}";
  }
  else
  {
    resizeSingleImage($filename, $size, $width, $resize_type);
    $srcset[] = "{$images_path}/{$filename}";
  }
  }


Because it looked right. I guess I am very wrong!

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 7:38 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6187
Location: Montreal, Canada
Let's walk through the getSrcSet function adding in some comments that describe the functionality for each segment of code. Should help clarify what's happening when and give you an idea of where you want to be adding in this new logic.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 7:39 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4138
Location: United Kingdom
But yes, I can see I am using resizeSingleImage in there... definitely wrong. I don't want want to play with the image. I just want to push it out as is, for 2560.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 7:54 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4138
Location: United Kingdom
Does it somehow go in here, NOT within the resize?

Syntax: [ Download ] [ Hide ]
if (file_exists($thumbnail_directory . DIRECTORY_SEPARATOR . $fullname)) {
// creates each one if the file exists
$srcset[] = "{$images_path}/{$fullname} {$size}w";
}

Just not sure how to do this in a loop, and state that for the 2560, it uses $filename and not $fullname.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 7:56 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6187
Location: Montreal, Canada
You don't need to worry about doing it in a loop. In fact, you don't want to. I suggested in a previous post where you could put it: viewtopic.php?f=1&t=143432&start=495#p707897

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 7:57 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4138
Location: United Kingdom
Getting there?
Syntax: [ Download ] [ Hide ]
if (file_exists($thumbnail_directory . DIRECTORY_SEPARATOR . $fullname)) {
// creates each one if the file exists
if (($resize_type == "categories" || $resize_type == "products" || $resize_type == "wide") && $size == "2560")
  {
    $srcset[] = "{$images_path}/{$filename} {$size}w";
  }
  else
  {
  $srcset[] = "{$images_path}/{$fullname} {$size}w";
  }
}
else
{
resizeSingleImage($filename, $size, $width, $resize_type);
$srcset[] = "{$images_path}/{$fullname} {$size}w";
}
}

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 8:09 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6187
Location: Montreal, Canada
You're still trying to do this inside that loop. Why? This is separate from trying to get the resized images.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 8:11 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4138
Location: United Kingdom
Because it has to be in a loop as that is where it outputs all the srcset code. Isn't it?

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 8:14 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6187
Location: Montreal, Canada
simonmlewis wrote:
Because it has to be in a loop as that is where it outputs all the srcset code. Isn't it?

Not really, no. The srcset array is generated in the getSrcSet function. We add the smaller sizes to it inside that loop because we have an array of resized images to iterate over. That's not what we're looking to do here, though. We have the file name for the original image and we just want to add that (and its width) to the srcset array before returning it. Look at the code I commented. That's where it should go. Step through the function and see what it's doing at each phase. You should understand why it belongs there. Where you're not clear, ask.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 8:18 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4138
Location: United Kingdom
In normal language, I can see the srcset[] is set above. So I just want to add onto that srcset[] if the image is a category, products or wide. And then add onto it:

the srcset[] array, and add on the $filename and $size w.

Is that what I am doing here?

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 8:25 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6187
Location: Montreal, Canada
simonmlewis wrote:
In normal language, I can see the srcset[] is set above. So I just want to add onto that srcset[] if the image is a category, products or wide. And then add onto it:

the srcset[] array, and add on the $filename and $size w.

Right.

simonmlewis wrote:
Is that what I am doing here?

No. What you are doing is best described thus:
Here's a file name and a resize type. Check if the file actually exists. If it does, get me a list of which smaller sizes should exist. For each size in that list, check if an image at that size exists. If it doesn't exist, create it. If it exists, or has just been created, add it to the srcset array. Also for each size in that list, add the full sized image to the srcset array (here's the problem: you're adding it multiple times by having it in that loop). Once you're done all that, split the array into a long string and return it to the caller.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 8:27 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6187
Location: Montreal, Canada
Then there's also the bit about $size == 2560. Not sure what that's about. Are you creating a new resized image at that size?

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 8:31 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4138
Location: United Kingdom
No. I'm asking it.... no wait. I don't need that in there. If it is one of those three, I'm just adding this line onto the array. I'm not asking what size it is, I'm just saying "add this line as well, for those resize_types, with this number on the end for 2560.

Right?

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 8:32 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6187
Location: Montreal, Canada
That sounds closer to what you want, yes. Do you see how to implement that in code?

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Mar 15, 2017 8:33 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4138
Location: United Kingdom
I See. So outside of that loop, I then add this into the srcset, if the resize_type is one of the three.

Syntax: [ Download ] [ Hide ]
$basename = pathinfo($filename, PATHINFO_FILENAME);
$extension = pathinfo($filename, PATHINFO_EXTENSION);

foreach ($widths as $size => $width) {
$fullname = $basename . '_' . $size . '.' . $extension;
if (file_exists($thumbnail_directory . DIRECTORY_SEPARATOR . $fullname)) {
$srcset[] = "{$images_path}/{$fullname} {$size}w";
} else {
resizeSingleImage($filename, $size, $width, $resize_type);
$srcset[] = "{$images_path}/{$fullname} {$size}w";
}
}

if ($resize_type == "categories" || $resize_type == "products" || $resize_type == "wide")
  {
    $srcset[] = "{$images_path}/{$filename} {$size}w";
  }
}

return implode(', ', $srcset);
}


But how do I tell it this is for 2560 ?
Do I add that in at the very top in the "case" section?

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 539 posts ]  Go to page Previous  1 ... 32, 33, 34, 35, 36  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group