3217 Posts in 853 Topics by 812 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2012 Views |
-
Checking Image Orientation

9 January 2009 at 10:31am
Hey all,
I apologize if I should be able to figure this out on my own, but I've been working on it for a few days and I just don't know how to write this. A veteran SS'er should probably find this pretty trivial...
I have a page that has a different layout based on whether a photo on the page is landscape or portrait oriented. I want to write a boolean function isHorizontal so that I can have a template that looks something like this:
...
<% if isHorizontal %>
// Horizontal code here
<% else %>
// Vertical code here
<% end_if %>Right now, I have created a function inside the Controller class for the page that goes like this:
function isHorizontal() {
$result = rand(1,2);
if($result==1) return true;
return false;
}This works exactly like I want it to, except it obviously just returns a random result for the image orientation rather than checking the image's height against its width. I've looked at the datamodel stuff and it's just a little bit over my head as I'm not great with PHP. If anyone is able to answer this, I would also be incredible appreciative if you could explain your answer. Thanks!
-
Re: Checking Image Orientation

9 January 2009 at 10:50am
Well, assuming you haven't subclassed your image and you're using the standard Image object, you're going to have to do some hacking.
public function Horizontal()
{
return $this->obj('NameOfImageField')->getHeight()<$this->obj('NameOfImageField')->getWidth();
}A better way to do it is to create a MyImage.php class
class MyImage extends Image
{
public function Horizontal()
{
return $this->getWidth() > $this->getHeight();
}
}and of course update your model to use the MyImage class rather than Image.
-
Re: Checking Image Orientation

9 January 2009 at 11:37am
Thanks for your quick response!
I decided to go with your second suggestion and call my subclass "GalleryImage." So I created a php file, GalleryImage.php and placed it in the code directory:
class GalleryImage extends Image {
public function Horizontal() {
return $this->getWidth() > $this->getHeight();
}
}However, after adding this (before updating my model) I rebuilt the database and I get this:
...
* GalleryImage
class GalleryImage extends Image { public function Horizontal() { return $this->getWidth() > $this->getHeight(); } }
Warning: Cannot modify header information - headers already sent by (output started at /home/homewerx/potteraestudios.com/site/sapphire/core/model/DatabaseAdmin.php:137) in /home/homewerx/potteraestudios.com/site/sapphire/core/Debug.php on line 151It also failed after updating my model, and after I changed the return statement to simply be false rather than doing the calculation. I must be missing something super obvious...
-
Re: Checking Image Orientation

9 January 2009 at 11:41am
is all of that wrapped in <?php tags? Looks like your code is just spilling out into the browser.
-
Re: Checking Image Orientation

9 January 2009 at 11:55am
Heh, I liked the idea so I submitted a patch and Sam has already merged into 2.3, so in the new (nearly ready for release) version, you will be able to do:
myImage->getOrientation()
...which will return a class constant, either:
ORIENTATION_SQUARE or ORIENTATION_PORTRAIT or ORIENTATION_LANDSCAPE.
So, in your page class you will be able to do:
function landscape() {
return $this->Image()->getOrienation() == Image::ORIENTATION_LANDSCAPE;
} -
Re: Checking Image Orientation

9 January 2009 at 7:10pm
I did indeed forget to put it in the <?php ... ?> tags. D'oh!
Works like a charm!
-
Re: Checking Image Orientation

10 January 2009 at 11:35am
Just FYI - I was converting an website I created several years ago to use SilverStripe rather than the hackish CMS I wrote in REALBasic. Despite the legacy code being a steaming mound of poo, it was easy to move everything over.
Check it out (the image orientation bit occurs in the gallery):
http://www.potteraestudios.com/And if you value proper XHTML/CSS coding, then for the love of God, do not check the source code. It's the most miserable table-based, inline-CSS garbage ever. But it's not worth fixing at this point ;)
-
Re: Checking Image Orientation

10 January 2009 at 3:08pm Last edited: 10 January 2009 3:08pm
looks like your flash intro is still linking to site/index.html, throws a 404 is you watch it all the way through ;)
have you thought about using the e-commerce module for the shop stuff? perhaps it's overkill but might be good to try (although I've heard getting Paypal to work can be a pain).
I found the navigation a little confusing, but I liked the site
| 2012 Views | ||
|
Page:
1
|
Go to Top |



