SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: Generate icon

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generate icon

    Hello everyone
    In fact, I am a beginner in programming, and I want a small script in PHP or JavaScript.
    The purpose of the script is to generate an icon from an image.
    The icon can learn from any part of the image.
    Thank you for your advice

  2. #2
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you can use image magick

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shayda thank you, but I am trying to do that in programming like PHP or JavaScript

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Take a look at the GD or ImageMagick PHP extensions.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    lol yeah next time i'll post a link :P

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here attached a source code that works well for resizing an image proportionnellement.J hope to make changes to just take any piece of an image into 95 * 95. Thank you
    Attached Files Attached Files

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello everyone,
    I have a script to resize the image proportionately, it takes the largest value (height or width), and the other value scales proportionally.
    The only problem with this script is that it does not set max height and max.

    For example, I wanted to generate an image with: max width: 171 and max height: 107
    If I take a picture with the denials width: 420, height 298, the proportional resizing cava give:
    420>> 298
    171>> x
    x = (298 * 171) / 420 = 121 (larger than I wanted for a max height 107).
    J'image what to do, but I do not know how to run it for a loop:
    H>> W
    171>> 121 (top of my max, I do not), I H - 1
    170>> 120 (top of my max, I do not) I'm making a H-1
    .....................................
    .....................................
    .....................................
    150>> 107 (<= 107, I take it)
    What is important for me is to respect the power proportional resizing does not distort the image, and at the same time does not exceed the max denied.
    I'm listening to your comments.
    Thank you in advance

  8. #8
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,027
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Here's a link to a post in the form I made containing a class that does basic image resizing. It's about 3 years old now, but a useful starting point all the same.

    http://www.sitepoint.com/forums/show...35&postcount=5

  9. #9
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I made a calculation of the proportion between width and height from the maximum dimensions and the same thing from
    actual dimensions of the picture: I then compared the two resizing in the appropriate direction depending on whether the result is
    positive or negative.
    Finally, my code works
    For cons, I still have that to make a thumbnail of my image, the principle and calculated the center of the image height and width

    and make a thumbnail from the center as shown in the image

    [IMG]www.mestestes.eu / proportion.jpg[/IMG]

    Here is my code that works well

    Code:
    <html>
    <head></head>
    <body>
    	<!--On affiche le formulaire d'envoi d'une image-->
    	<center>
    	<br /><hr />
    
    	<form method="post" enctype="multipart/form-data" action="upload.php">
    	<p>
    	
    	
    	
    	   Le nom de l'image redimensionner avec 95 ,95
    	   <input type="text" name="video"><br><br>
    	   
    	  
    	   
    	<input type="file" name="fichier" size="30">
    	<input type="submit" name="upload" value="Uploader">
    	</p>
    	</form>
    	</center>
    	
      </body>
      </html>
    
    [/PHP]
    
    
    [PHP]
    <?php
    
    
    $nomImage=$_POST['video'];
    
    if( isset($_POST['upload']) ) // si formulaire soumis
    {
        $content_dir = 'upload/'; // dossier où 
    
    sera déplacé le fichier
    
        $tmp_file = $_FILES['fichier']['tmp_name'];
    
        if( !is_uploaded_file($tmp_file) )
        {
            exit("Le 
    
    fichier est introuvable");
        }
    
        // on vérifie maintenant l'extension
        $type_file = $_FILES['fichier']['type'];
    
        if( !
    
    strstr($type_file, 'jpg') && !strstr($type_file, 'jpeg') && !strstr($type_file, 'png') && !strstr($type_file, 'bmp') && !strstr
    
    ($type_file, 'gif') )
        {
            exit("Le fichier n'est pas une image");
        }
    
        // on copie le fichier dans le dossier de 
    
    destination
    	
    	$ext = substr($_FILES['fichier']['name'], strrpos($_FILES['fichier']['name'], '.'));
    
    	$name_file = 
    
    $nomImage.$ext;
    	echo $name_file;
    
    	
    	//fonction pour changer les dimentions des fichiers
      function redimensionner
    
    ($file, $maxwidth, $maxheight) {
    
    list($rawwidth, $rawheight, $type) = @getimagesize($file);
    
    				if 
    
    ($maxwidth < $rawwidth && $rawwidth >= $rawheight) {   
    				$width =  $maxwidth;   
    				
    
    $height = ($width / $rawwidth) * $rawheight;  }   
    				
    				if ($maxheight < 
    
    $rawheight && $rawheight >= $rawwidth) {   
    				$height = $maxheight;   
    				
    
    $width = ($height /  $rawheight) * $rawwidth;  }  
     	
     
    				if($height > $maxheight) {  
    			
    
    	$width = ($maxheight / $height) * $width;  
    				$height = $maxheight; } 
    				
    				
    				
    				
      $imgbuffer = 
    
    imagecreatetruecolor($width, $height);
    
      switch($type) {
    
        case 1: $image = imagecreatefromgif($file); break;
    
        case 2: $image = 
    
    imagecreatefromjpeg($file); break;
    
        case 3: $image = imagecreatefrompng($file); break;
    
        case 4: $image = imagecreatefrombmp
    
    ($file); break;
    
        default: exit("Tried to create thumbnail from $file: not a valid image");
    
      }
    
      if (!$image) exit("Image creation 
    
    from $file failed for an unknown reason. Probably not a valid image.");
    
      else {
    
        imagecopyresampled($imgbuffer, $image, 0, 0, 0, 
    
    0, $width, $height, $rawwidth, $rawheight);
    
        imageinterlace($imgbuffer);
    
        switch($type) {
    
    	
    	
    	
          case 1: 
    
    $image = imagegif($imgbuffer, $file, 80); break;
    
          case 2: $image = imagejpeg($imgbuffer, $file, 80); break;
    
          case 3: 
    
    $image = imagepng($imgbuffer, $file, 7); break;
    
      
    
        }
    
      }
    
    }
    
    
    if( preg_match('#[\x00-\x1F\x7F-\x9F/\\\\]#', $name_file) )
    
    {
    
      exit("Nom 
    
    de fichier non valide");
    
    }
    
      else if( !move_uploaded_file($tmp_file, $content_dir . $name_file) )
    
    {
    
      exit("Impossible de copier le 
    
    fichier dans $content_dir");
    
    } 
    
    redimensionner($content_dir.$name_file,171, 107);
    
    }
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •