
1internet
Members-
Posts
136 -
Joined
-
Last visited
Everything posted by 1internet
-
trying to identify categories from products in a url
1internet replied to 1internet's topic in PHP Coding Help
Ok, I get it, this is not possible to determine, so I need to create validation so that the product and categories do not have the same urls. So if I do that, should I do the look up for the last array element, like I said at the start. Would that be the best way? Or is it going to slow down things. -
trying to identify categories from products in a url
1internet replied to 1internet's topic in PHP Coding Help
Well I can't change the urls. So any ideas? -
I am working on an e-commerce site. to There are two types of pages, products and categories. I can't work the best way to identify them in the htaccess. example urls: site.com/category/product site.com/category/sub-category/product1 site.com/category/sub-category/sub-sub-category There are essentially an unlimited level of sub-categories. So I am guessing I need to explode the url $url = (explode("/",$url); So from there I will have an array of urls. I thought the best thing to do would take the last element in the array, and check to see if it is in the database for the products. But then what if the products and categories have the same same? Any other ideas?
-
@Jessica Yes, it did, and I get the logic now too, it totally makes sense. That's awesome, thanks a lot.
-
@Sen So I want to create thumbnails, all of equal sizes, e.g. 100x100. But the original sizes could be any dimensions, e.g. 700x400, 1200x600, 300x500, etc. So I want to resize the image so the width is 100, if it means that the height will be greater than 100, if not then then I will resize the height to 100, so that the width will be greater than 100. Then the dimension that is greater than 100,( e.g. if we resize 600x400 to 150x100, thus the 150 is greater than 100), will be subtracted from 100, 150-100 = 50. We then divide the 50 by 2 giving us 25, and remove 25px either side of the image. @The Web Mason Thats what I can am trying to do, as it looks like you have cropped evenly from the top and the bottom, but I don't quite follow the logic.
-
$temp = $_FILES['image']['tmp_name']; $image_size = getimagesize($temp); $image_width = $image_size[0]; $image_height = $image_size[1]; $image_ratio = $image_width/$image_height; $image_name = 'crop_test'; $new_width = 500; $new_height = 250; $new_ratio = $new_width/$new_height; $offset_type = null; $resized_width = ''; $resized_height = ''; if($image_width == $image_height){ if ($new_width > $new_height) { $resized_width = $new_width; $resized_height = $new_width; $offset_type = 'height'; $offset = $resized_height - $new_height; } elseif ($new_height > $new_width) { $resized_height = $new_height; $resized_width = $new_height; $offset_type = 'width'; $offset = $resized_width - $new_width; } else { $resized_width = $new_width; $resized_height = $new_height; $offset == 0; } } if($new_ratio > $image_ratio){ $resized_width = $new_width; $ratio = $resized_width/$image_width; $resized_height = round($image_height*$ratio); $offset_type = 'height'; $offset = $resized_height-$new_height; } if($image_ratio > $new_ratio){ $resized_height = $new_height; $ratio = $resized_height/$image_height; $resized_width = round($image_width*$ratio); $offset_type = 'width'; $offset = $resized_width-$new_width; } if($offset_type == 'height'){ $src_y = round($offset/$ratio/2); $src_x = 0; } if($offset_type == 'width'){ $src_x = round($offset/$ratio/2); $src_y = 0; } $extension = '.jpg'; $src_image = imagecreatefromjpeg($temp); $dst_image = imagecreatetruecolor($new_width, $new_height); imagecopyresampled ($dst_image , $src_image, 0, 0, $src_x, $src_y, $new_width, $new_height, $image_width-$src_x, $image_height-$src_y); imagejpeg($dst_image , 'crop/'. $image_name.$extension, 100); So I want it to be able to crop the center of an image, if the width or height exceeds the $new_width or $new_height, once the image has been re-sized. I just used 500 and 250 as an example of the new image, but this will be arbitrary.
-
Thanks, but all that did was create some black areas on the image.
-
I understand all that side, I am just trying to work out how I cut e.g. 50px from each side, I can only manage to get it from either the left or right, but not both.
-
So I have imagecopyresampled ($dst_image , $src_image, 0, 0, $src_x, $src_y, $new_width, $new_height, $image_width-$src_x, $image_height-$src_y); src_x and src_y are the co-ordinates I want to crop the image from, but I am not sure how how to create the co-ordinates of where to cut them to - i.e. set the crop height and width. I have been working on this for hours testing every permutation under the sun, and cant figure it out. How is this done?
-
No, but I can calculate that easily, I was just using it as an example, as to what to do from there.
-
UPDATE imagecopyresampled($new_image, $old_image, 66, 0, 0, 0, $new_width-133, $new_height, $image_width, $image_height) I thought this might work, but doesn't seem to either, but might hopefully shed some more light on what I am trying to achieve.
-
e.g. if image is 500x300 and I want it to be 200x200 then the new width and height will be 200x200 but first the new dimensions of the image will be created, so the height will go from 300 to 200 and then the width will become 500 x 200/300 = 333 then we will use 333-200 = 133 this is how much we need to crop the width but it needs to be cropped each side so, 133/2 = 66 so we will crop 66 each side So I imagine it will be something like $new_image = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height) Only instead of 0,0,0,0 there will be 66, in there somewhere, but I have experimented with it, with no luck. Can't really get my head around this here, I am sure there is some easier solution. Appreciate all help.
-
It works with top, do I really need left or right? Is vertical placement enough?
-
I tried that, but left won't work for different window sizes. How do I solve that?
-
I have an issue in IE8 where my div is displayed about 50px closer to the top than in FF or Chrome, or IE9. I think I have narrowed it down to it being the position absolute. I am declaring an HTML5 doctype, but still facing this issue. It also occurs for position: relative. #slider { position: absolute; margin-left: 315px; margin-top: -350px; z-index: 1; } Any easy solution to get around this?
-
I am not entirely sure what this is called, but say for example you have some text on a site, and you want to edit it right there and then, and you just click on the text, and it changes to a text field and you edit the text, then onblur it updates the text with the new content form the text field. What is this called, and what is the best and easiest method of doing it?
-
accessing a variable from procedural through a class
1internet replied to 1internet's topic in PHP Coding Help
Yea, I do, but sometimes I just like to make sure there isn't some standard or much simpler way to do things. It didn't work though. So I think this is the best way class test { function method($x) { echo $x; } } $thetest = new test; if (isset($testing)) $thetest->method($testing); -
accessing a variable from procedural through a class
1internet replied to 1internet's topic in PHP Coding Help
Ok so what if the variable may not be set? class test { public function method($x=null) { if(isset($x)) echo $x; } } $testing = 'it works'; $test = new test; $test->method($testing); Would that work? -
I am trying to access a variable through a class, and can't work out how to this. class test { function method() { if (isset({$testing})) { echo {$testing}; } } } $testing = 'it works'; $thetest = new test; $thetest->method(); Is this even possible, or have I got very confused?
-
So if you have a submit button in a class public function submit() { <input type="submit" name="'.$this->submit.'" value="'.$value.'"/>'; } But then you have a text form that wants to detect if the form has been submitted, and if it has been submitted, you want it to display the value in the field, how would you do that, as far as I could get was this, but it's not working, even after a lot of playing around. public function text($name) { $this->name = $name; $label = ucwords($this->name); $name = strtolower(str_replace(' ', '', $this->name)); if(isset($this->submit)) $this->value = $_POST[$name]; else $this->value = ''; $this->field = ' <input type="text" name="'.$name.'" value="'.$this->value.'"/>'; } So the issue is that it doesn't seem to detect if the variable has been set (form submitted). I am guessing there is some way to do this.
-
Sure, I am far from MVC full potential. So once you fully grasp OOP, do you ever even use procedural any more? I am trying to do as much OOP as possible until I truly get it.
-
Sure I understand, I have got into MVC, and understand it, but I am not quite there yet. I haven't quite grasped OOP yet, and still thinking too procedural, but I am trying to get there. Starting with a "simple" form. Any advice and tips are appreciated.
-
What about if I returned the variable from the class1, and executed from class 2 from there. Perhaps if I tell you what I am trying to accomplish here, there may be a better way. I want to create a form with oop. But I also want the form to update the db, and go through a validation process. The form will have an arbitrary number of fields with different field names. I have to create the form first, so that the field names and number of fields is known. Then I have to create the validation by pulling these variables from the form. And although the validation will be created secondly, it must be displayed first on the page, i.e. before the header info. Any better suggestions on how to go about this?
-
If I have class class1 { public function variable($str) { $this->str = $str } } class class2 { public function get() { echo class1->str; } } How can class2 get the 'str' variable from class1, do I need to create an extension? So would would instantiate it with $str = new class1(); $var = $str->str('test'); $str1 = new class2(); $str1->get();
-
Ok, so there is no code that can do something like: display preloader until page loaded?