Jump to content

Accipiter

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Accipiter's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. (One last question. How do I set a topic as Solved?)
  2. I finally succeeded. If anyone else needs to set a selected part transparent, this is one way: [code]// $thumb is the user uploaded image, resized to the same width and height as the overlay. // Adding the overlay image upon the users pictures $overlay = imagecreatefrompng($overlay_image_path); imagealphablending($overlay, true); imagecopy($thumb, $overlay, 0,0,0,0, $width, $height); // Reducing the colors to 255 (not 256. I want the last one available) imagetruecolortopalette ($thumb, false, 255); $r = $g = $b = 0; // Finding a unique, unused color while( imagecolorexact($thumb, $r, $g, $b) != -1 ) { if( $r <= $g ) $r++; elseif( $g <= $b) $g++; else $b++; } imagecolorset ( $thumb, 255, $r, $g, $b );  // Set the last, unused index, to our unused color // The mask is a Black&White image with the White set to transparent. $mask = imagecreatefromgif($mask_image_path); $imaskbg = imagecolorexact ( $mask, 0,0,0 );  // Get the palette index of the black color imagecolorset( $mask, $imaskbg, $r, $g, $b );  // Change the black color to our unused color imagecopy( $thumb, $mask, 0,0,0,0,$width, $height); // Copy it over. The white will be transparent. imagecolortransparent($thumb, 255);  // Set our color to transparent. header ("Content-Type: image/gif'"); imagegif($thumb);[/code] It worked for me atleast :)
  3. Hi all, I am trying to create automatically generated avatars. The user uploads an image, and then I copy my "foreground" on top of it (in shape of a wreath). So.. What I have is a truecolor resource in a specific width and height But as I use imagegif() to send it, I want the "background" colored pixels to be transparent. Example of how it looks now: [url=http://www.thesodality.org/test.php]http://www.thesodality.org/test.php[/url] The [color=blue]blue[/color] is the user image, the entirely brown ones (not the ones antialiasing the green leaves) should be transparent. My two options are: 1) Using a black and white mask image. This way I won't risk making any pixels within the user image transparent. 2) Setting the brown color to transparent. If the users image contains the exact same brown, it will get holes :P Unfortunately, I have failed to succeed with any of the two. Help is highly appreciated! /Accipiter Ps. If you want to see how I've done it: [code] // $thumb is the user uploaded image, resized to the same width and height as the overlay. $overlay = imagecreatefrompng($overlay_image_path); imagealphablending($overlay, true); imagecopy($thumb, $overlay, 0,0,0,0, $width, $height); // This part fails! $image = imagecreatetruecolor($width, $height); $transparent = imagecolorallocate($image, 223,192,137); // Those numbers are the brown color imagecolortransparent($image, $transparent); imagecopy($image, $thumb, 0,0,0,0, $width, $height); header ("Content-Type: image/gif"); imagegif($image);[/code]
  4. Hi all, I have no idea if this is the right forum, but none seemed to match. But since it is with php that I will send the headers, I will ask here nontheless. I am creating an image gallery site. When I upload an image, it automatically creates a thumbnail from specified coordinates on the image. When I change these coordinates, the old thumb is deleted and a new is created. Problem is that, after submitting the new coordinates Firefox (1.5 atleast) doesn't revalidate the thumbnail preview image but uses an old cached one. (IE actually works fine). Though, if I press submit on the page where I edit the image information (like description), then it revalidates the image. But, both the Thumbnail edit and the Image information Edit page has the same URL. Why is this? Headers you say. Well, yes. This in an example of the headers that I send with the thumbnail: [tt]Content-Location: thumb.php Vary: negotiate TCN: choice Accept-Ranges: bytes X-Powered-By: PHP/4.3.1 Content-Length: 6161 Cache-Control: public no-cache must-revalidate Pragma: Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Disposition: inline; filename=big3_thumb.jpg ETag: "5_1169038031" Content-Type: image/jpeg [/tt] If you wish to help, I just set up an account on the site and uploaded an image which you can try it out with. Just log on and I have provided a link to the image on the index page. URL: [url=http://www.jirenius.com]http://www.jirenius.com[/url] Username: [b]phpfreaks[/b] Password: [b]phpfreaks[/b] Any advice is appreciated. /Samuel Jirenius
  5. Taking your suggestion, I tried. Yay! It worked, just like I wanted it to. Thanks alot for the help! It might have sounded trivial, but just JS is completely new to me and I just had no idea what I could and couldn't do.
  6. Well, I realizes that, what I suggested myself worked pretty well  :-[ But what problem still remains is that the value of the Submit-button "send" will not be sent through the link. Can I make it somehow?
  7. Hi all, I am doing a form for uploading/editing an image in an online gallery. The form passes data to the PHP script by the Post method, and if the submit button has been clicked, the data is checked, fixed and finally uploaded to the DB. Now, what I also want is to have a link (for those with js enabled browsers) for editing the thumbnail. If one presses the link a normal submit should be sent, but in addition, another value should be set to [color=green]true[/color] so that after the data has been updated in the DB, the PHP script should redirect to the thumbnail edit page if this value is set. From what I've read so far on the net, I can't directly use the POST with Javascript, but will have to send the data through the form. Can I have a hidden value that I can change with the script then? I am completely new to Javascript though. [code]<script type="text/javascript"> <!-- function thumbsubmit() {   var x=document.getElementById("formtable_form");   x.editthumb.value=1;   x.submit(); } //--> </script> <form action="upload.php" enctype="multipart/form-data" method="post" name="formtable_form"> <input type="hidden" name="editthumb" value="0" /> .. <script type="text/javascript"> <!-- document.write('<br /><a href="javascript:thumbsubmit();">Edit thumbnail<\/a>'); //--> </script> ... <input type="submit" name="send" value="Submit" /> </form>[/code] Okay.. I don't even know if it this code works. Will that Hidden field be changed before submitted? And if I write like this, the "send" will not be submitted, but I would need it to be sent too. Any help and/or suggestions is welcome!
  8. You can't use a variable in a function if it is declared outside of it. If you wish to use one, you have to set it as global, like this: [code]function f_ret_error($element) { global $error, $return_error; // This will tell PHP that $return_error declared outside the function should be used inside too if ($error[$element] == 1) { echo $return_error[$element];} } function f_err_mem($element) { global $error, $profile; if ($error[$element] == 0){ echo $profile[$element];} else { echo $_POST[$element];} }[/code] Observe that $_POST ($_GET, $_FILES etc) are already global variables, so called Superglobals. Good luck with further coding! :)
  9. Reading your question, I was slightly confused in what you tried to do (eventhough it was thouroughly explained). The point which I wasn't sure about was: When you say 'collide', do you mean you want the same value to be accessed both through the [color=blue]level0a[/color] array as well as through the [color=blue]level0b[/color] array? I mean, do you want: [code]$list['level0a']['level1a']['level2b'] = 12; echo $list['level0b']['level1b']['level2b'];[/code] to show the value: [color=blue]12[/color] Or will the information stored under one of the branches in this array only be accessible through that branch?
  10. (Ah, just as an addition) Ofcourse, as I wrote it now, it will load the image into the GD and then send it as a JPEG no matter if it was scaled down or not, as long as a width and height was given. My suggestion was just to give you an idea how GD works. Hope it helps you along the way!
  11. Well, I think I know what is wrong. I assume you've stored the image file (jpg, gif, png or so) in the database. Then, you must load the image into the GD. The image resource (which should be $img) and the image file ($row[$imgnum]) is in VERY different format. Try like this instead. [code] if($mwidth != "" && $mheight != "")  {     // Load image to GD from the data     $img = imagecreatefromstring($row[$imgnum]);     // Get image size and scale ratio     $width = imagesx($img);     $height = imagesy($img);     $scale = min($mwidth/$width, $mheight/$height);     // If the image is larger than the max shrink it     if ($scale < 1) {         $new_width = floor($scale*$width);         $new_height = floor($scale*$height);         // Create a new temporary image         $tmp_img = imagecreatetruecolor($new_width, $new_height);         // Copy and resize old image into new image         imagecopyresized($tmp_img, $img, 0, 0, 0, 0,                         $new_width, $new_height, $width, $height);         imagedestroy($img);         $img = $tmp_img;     }         // If you really wish for the image to be of the same format as $imagetype,         // then you can make a switch-case here. Now I set it so send the thumb as jpeg         header("Content-type: image/jpeg"); imagejpeg($img); } else {         // set the header for the image         header("Content-type: $imagetype");         echo $row[$imgnum]; }[/code]
  12. Reading a little about it on other places on the net, it seems there is no actual limit (atleast not a limit I would ever reach). Though, it might make it slower, but this is probably just when you do a [i]ls[/i] or so. But to be on the safe side, I will make it so that the files can be stored in multiple folders. Thanks for all your input!
  13. And to suggest which functions to use with the data you pulled from your database: [url=http://se2.php.net/function.imagecreatefromstring]http://se2.php.net/function.imagecreatefromstring[/url] The function will autodetect what type (jpg/gif/png/etc.) of image it is in your variable and create it. Then you can just manipulate it with the other GD functions. With the functions [url=http://se2.php.net/manual/en/function.imagesx.php]http://se2.php.net/manual/en/function.imagesx.php[/url] [url=http://se2.php.net/manual/en/function.imagesy.php]http://se2.php.net/manual/en/function.imagesy.php[/url] you can retrieve the image width and height. Good luck! :)
  14. Sorry for "busting in". But yes, I was also thinking about parsing it all, but I realized it would grow more complicated unless one would rely on a constant number of characters per person and value (which I wasn't sure would be reliable). Fun though to see how another person would face the same problem :)
  15. Oh! I see someone else has also taken up the quest (I am sorry). Well, I was bored and it looked like a fun question so I made a suggestion on how to parse the text. I mainly used the fact that it was split up with multiple spaces. So, it creates a multidimensional array $parsed_league You can use print_r($parsed_league); if you want to see how it is structured. I also made an example of how to output it with spaces to separate names with their "values". Maybe it can be done more easilly, but I am pretty new to php :P Good luck! (Oh bummer! I just noticed I totally forgot to output what category they were the leader of. I edited it to do it now) [code]<?php $filename = "http://csbl.net/league_html/leaders.htm"; $file = file($filename); $data = array(); foreach ($file as $line) {   $data[] = strip_tags($line); } $groups = array('Season Batting Leaders', 'Season Pitching Leaders'); $league = ''; $types = array(); $parsed_list = array(); $wait_for_empty = true; foreach($data as $row) { $row = trim($row); if( empty($row) ) { $wait_for_empty = false; } else { foreach($groups as $testgroup) { if( strpos($row, $testgroup) !== false ) { $league = trim(str_replace($testgroup, '', $row)); // Fetches which league $types = array(); // Should not be needed. Just precaution $wait_for_empty = true; } } if( !$wait_for_empty && !empty($league) ) { if( empty($types) ) // { // trim() removes the spaces at the start and end of the row. // The preg_replace turns any multiple of spaces into double space, which is the separator in the explode $types = explode( '  ', preg_replace('/\s{3,}/', '  ', trim($row))); } else { foreach($types as $type) { $row = preg_replace('/^\s*1?\s+/', '', $row);  // Removes the spaces and number at start. $length = strpos($row, '  '); $parsed_list[$league][$type]['name'] = substr($row, 0, $length); $row = substr($row, $length); // Cut away the name from the string $row = ltrim($row); $length = strpos($row, '  '); $length = empty($length) ? strlen($row) : $length; // To also grab the last value if spaces are missing $parsed_list[$league][$type]['value'] = substr($row, 0, $length); $row = substr($row, $length); } $types = array(); // Clear the array as we've collected the desired information $wait_for_empty = true;  // Don't parse any row until we hit an empty line } } } } echo '<pre>'; foreach($parsed_list as $name=>$league) { echo "\n".$name."\n"; foreach($league as $type_name=>$type) { echo "\n".$type_name."\n"; echo $type['name'].str_repeat(' ', 40 - strlen($type['name'].$type['value'])).$type['value']."\n"; } echo "\n"; } echo '</pre>'; ?>[/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.