Problem??

Discussion in 'PHP' started by cynical_tear, Nov 3, 2009.

  1. #1
    I have a image uploading webiste... I am facing 2 problems in it...

    1) I don't want user to upload a image which has single quote(') or Double Quotes(") in the file name. ex. jonn'simage.jpg...
    I tried using (strstr($imagename,'\'')) and (strstr($imagename,'\"')) function but it isn't working..

    2) Image Resizing : i want to display the image within 750xX px box, ie, width=750px and height can vary... so when the image is of dimension 800x500px, then i want that its width reduces to 750px and its height varies in ratio with its width but if the image has dimensions 500x400px or 400x800px then i dont want to change anything in the image and want to displat it as it is...

    Can anyone help???
     
    cynical_tear, Nov 3, 2009 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    Resizing can be done via imagemagick like:
    
    exec("convert image.jpg -resize 750x resize_image.jpg");
    
    PHP:
    Usually you need to provide full path to initial and result images.

    I usually use
    
    str_replace();
    
    PHP:
    to replace some symbols in string.
     
    AsHinE, Nov 3, 2009 IP
  3. cynical_tear

    cynical_tear Peon

    Messages:
    107
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thnkyou Ashine for repling my query..

    The 2nd part of my 2nd question still remains unanswered...
    How can i change the height of the image with accordance to the width using the function you provided..
     
    cynical_tear, Nov 3, 2009 IP
  4. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #4
    Last edited: Nov 3, 2009
    AsHinE, Nov 3, 2009 IP
  5. cynical_tear

    cynical_tear Peon

    Messages:
    107
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thankyou ASHINE for helping me out..
     
    cynical_tear, Nov 3, 2009 IP
  6. cynical_tear

    cynical_tear Peon

    Messages:
    107
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I am going through the link you provided me but i am not getting how to use it... what is the code and how to write it in php...??? can you please help me
     
    cynical_tear, Nov 3, 2009 IP
  7. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #7
    Ok, examples:
    
    function ConvertUsingOnlyWidth($from, $to, $max_width = 0)
    	{
    		exec("convert " . $from . " +profile \"*\" " . "-resize \"" . $max_width .">\" " . $to);
    	}
    
    PHP:
    this will resize image only if its width is bigger than $max_width

    
    function ConvertUsingOnlyWidth($from, $to, $max_width = 0)
    	{
    		exec("convert " . $from . " +profile \"*\" " . "-resize \"" . $max_width ."\" " . $to);
    	}
    
    PHP:
    this will resize iamge in any case, so it will enlarge small images and shrink big ones.

    Usage:
    
    $path = "/mounted-storage/home1s8b/sub005/sc30r21-RGCK/site.info/";
    ConvertUsingOnlyWidth($path."shine.jpg",$path."tmp/shine.jpg",800);
    
    PHP:
    Make sure your tmp directory is writeable by script.
     
    AsHinE, Nov 4, 2009 IP
  8. cynical_tear

    cynical_tear Peon

    Messages:
    107
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks allot for our help..

    I really appriciate that........
     
    cynical_tear, Nov 4, 2009 IP