help please in this code ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fuchsia555
    New Member
    • Dec 2009
    • 56

    help please in this code ?

    Hi
    i have image script , and images have my own watermark on the bottom , size of this watermark 15 pixel ,,, i just need help in the code below to tell php to ignore reading this watermark while creating thumbnails for the images , i just want the watermark disappear in thumbnails only
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    I don't think anyone will try to wade through your code in order to help you *fix* it. If they do, kudos to them. Unless you have an actual error, then I'm going to ignore the code.

    Basically, the process you want to follow is this:
    1. Make the main GD image and save it into a variable (main)
    2. Duplicate the GD image and save that into another variable (thumbnail)
    3. Add the watermark to the first GD image (main)
    4. Resize the second GD image to the desired thumbnail size (thumbnail)
    5. Save both images to the disk

    Comment

    • fuchsia555
      New Member
      • Dec 2009
      • 56

      #3
      Thanks for replay dear kovik
      but i don't need to watermark images through script
      my images already watermarked with desktop software
      all i need that to tell php ignore 15 pixel from height bottom while creating thumbnail , because i don't want the watermark appear in thumbnails images , i think i need something like $crop = 15 pixel
      and minus it from height i don't know how to do it exactly

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        Oh, you want to crop it? Use imagecopyresamp led() and utilize the src_h parameter to tell PHP what part of the image to copy.

        Comment

        • fuchsia555
          New Member
          • Dec 2009
          • 56

          #5
          here is an example for image and watermark


          but how can we set imagecopyresamp led()
          in this script to work together

          here is code that show how thumbnail work in my script
          Code:
          #create thumb
          					$thumb = gd_fit($image,$settings['thumbxy']);
          
          					#save thmb first
          					imagejpeg($thumb,"$th/$id.jpg",$settings['thumbuality']);
          					imagedestroy($thumb);
          					#then save actual jpeg
          					imagejpeg($image,"$im/$id.jpg",$settings['quality']);
          					imagedestroy($image);
          					
          					$iptc = new iptc("$im/$id.jpg");
          					if($cimg[0] == 1) {
          						#it is gif keep in data
          						write_file("$im/$id.jpg",load_file("$th/$id.jpg"));
          						write_file("$im/$id.gif",$cimg[1]);
          						$iptc->set(DPI_GIF,"GIF");
          					}
          
            function gd_fit(&$image, $target) { 
              
                  //takes the larger size of the width and height and applies the  
                  //formula accordingly...this is so this script will work  
                  //dynamically with any size image 
                  
                  $width = gd_width($image);
                  $height = gd_height($image);
                  
                  if ($width > $height) { 
                      $percentage = ($target / $width); 
                  } else { 
                      $percentage = ($target / $height); 
                  } 
                  
                  //gets the new value and applies the percentage, then rounds the value 
                  $width = round($width * $percentage); 
                  $height = round($height * $percentage); 
                  
                  //returns the new sizes in html image tag format...this is so you 
                  //can plug this function inside an image tag and just get the 
                  
                  return gd_resize($image,$width,$height);
                      }
                function gd_width(&$image) {
                  return imagesx($image);
              }
              function gd_height(&$image) {
                  return imagesy($image);
              }    
          
              function gd_imagewidth($fname) {
                  list($width, $height) = getimagesize($fname);         
                  return $width;
              }
              function gd_imageheight($fname) {
                  list($width, $height) = getimagesize($fname);         
                  return $height;
              }       
          
          
          
          	    function gd_resize(&$image,$w,$h) {
                  $ret=@imagecreatetruecolor($w, $h); 
                  @imagecopyresampled ($ret,$image, 0, 0, 0, 0, $w, $h, imagesx($image), imagesy($image));  
              
                  return $ret; 
              }

          Comment

          • kovik
            Recognized Expert Top Contributor
            • Jun 2007
            • 1044

            #6
            1. Use an imagecreatefrom * function (i.e. imagecreatefrom jpeg()) to build the GD image resource from a file
            2. Use imagesx() and imagesy() to get the width and height of the GD image resource, respectively.
            3. Use the width, height, and imagecreatetrue color() to build a canvas for a new image that is the desired size using the original width and height
            4. Use imagecopyresamp led() to copy the desired contents of the first GD image resource (as the source) to the second GD image resource (as the destination).
            5. Use an image* function (i.e. imagejpeg()) to save the file.

            Comment

            • fuchsia555
              New Member
              • Dec 2009
              • 56

              #7
              i think we're close to solve it , i will follow your steps by it's number with my codes

              step 1-
              Code:
               function gd_loadimage($fname) { //ignore ext e.g. for xbm and xpm load jpg
              		$arr = explode(".",$fname);
              		$ext = strtolower($arr[count($arr)-1]);
              		$func = 'imagecreatefrom';
              		switch($ext) {
              			case 'jpg' :
              			case 'jpeg':
              			case 'jpe' :  $func .= 'jpeg'; break;
              			case 'png' :  $func .= 'png'; break;
              			case 'gif' :  $func .= 'gif'; break;
              			case 'xbm' :  $func .= 'xbm'; break;
              			case 'wbmp':  $func .= 'wbmp'; break;
              			
              			/*case 'gif' :  $func .= 'jpeg'; break;
              			case 'xbm' :  $func .= 'jpeg'; break;
              			case 'xpm' :  $func .= 'jpeg'; break;
              			case 'wbmp':  $func .= 'wbmp'; break;
              			case 'bmp' :  $func .= 'jpeg'; break;
              			case 'ico' :  $func .= 'png'; break;
              			case 'cur' :  $func .= 'jpeg'; break;
              			case 'ani' :  $func .= 'jpeg'; break;
              			case 'txt' :  $func .= 'jpeg'; break;*/
              			
              		
              
              		}
              		if(!function_exists($func))
              			return false;
              		
              		$res = @$func($fname);;
              		if(!$res)
              			$res = @imagecreatefromjpeg($fname);
              		if(!$res) return false;
              		
              		return $res;
              		
                  }
                  function gd_loadimage_orig($fname) {
              		if(!file_exists($fname)) return false;
              		
              		$arr = explode(".",$fname);
              		$ext = strtolower($arr[count($arr)-1]);
              
              		if($ext=='jpe' or $ext == 'jpg') $ext = 'jpeg';
              		
              		$func = "imagecreatefrom$ext";			
              				
              		if(!function_exists($func)) 
              			return false;
              
              		//return $func($fname,$ext=='ico'?16:'',$ext=='ico'?32:100);
              		return $func($fname);
              		
                  }



              step 2-
              Code:
                  function gd_width(&$image) {
              		return imagesx($image);
                  }
                  function gd_height(&$image) {
              		return imagesy($image);
                  }    
              
                  function gd_imagewidth($fname) {
              		list($width, $height) = getimagesize($fname); 		
              		return $width;
                  }
                  function gd_imageheight($fname) {
              		list($width, $height) = getimagesize($fname); 		
              		return $height;
                  }


              step 3-

              creating thumb is using this code
              Code:
              #create thumb
              $thumb = gd_fit($image,$settings['thumbxy']);
              so it's using gd_fit function , this function here
              Code:
              	function gd_fit(&$image, $target) { 
              	
              		$width = gd_width($image);
              		$height = gd_height($image);
              		
              		if ($width > $height) { 
              			$percentage = ($target / $width); 
              		} else { 
              			$percentage = ($target / $height); 
              		} 
              		
              		//gets the new value and applies the percentage, then rounds the value 
              		$width = round($width * $percentage); 
              		$height = round($height * $percentage); 
              		
              		//returns the new sizes in html image tag format...this is so you 
              		//can plug this function inside an image tag 
              		
              		return gd_resize($image,$width,$height);
              		
              	}

              step 4- the return from gd_fit >> function gd_resize ,,,, and it's code
              Code:
                  function gd_resize(&$image,$w,$h) {
              		$ret=@imagecreatetruecolor($w, $h); 
              		@imagecopyresampled ($ret,$image, 0, 0, 0, 0, $w, $h, imagesx($image), imagesy($image));  
              	
              		return $ret; 
                  }
              step 5- imagejpeg and it's code >>
              Code:
                   function write_jpeg(&$image,$fname,$quality=100) {
              		if (function_exists("imagejpeg"))
              			return @imagejpeg($image,$fname,$quality); 
              		return false;
                  }


              so the step number 4 that must be edit , we're close to it , i don't know exactly how to do it

              Comment

              • kovik
                Recognized Expert Top Contributor
                • Jun 2007
                • 1044

                #8
                I told you everything that you need to know, MUCH more than I even should have told you. Write the code, debug it, find out where its going wrong, THEN ask for more help.

                Comment

                • fuchsia555
                  New Member
                  • Dec 2009
                  • 56

                  #9
                  Thank you Mr Kovik so much
                  i'll try to do it
                  i really love this forum

                  Greetings and Respect

                  Comment

                  Working...