create , rename , save image php

Discussion in 'PHP' started by mirosoft1, Sep 8, 2010.

  1. #1
    Dear all;
    i made page to write text on image but my problem is:
    1.want to rename the name the new image (text on image)
    2.want to insert this image into mysql database

    this is the code create the image

    
    error_reporting(E_STRICT);
    $image=$_POST['background_name'];
    $text=$_POST['text'];
    $font=$_POST['font_name'];
    $color=$_POST['text_color'];
    $align=$_POST['text_alignment'];
    $im = @imagecreatefromjpeg($image);
    $width = imagesx($im);
    
    $height = imagesy($im);
     if($color==red)
    {
    $color = imagecolorallocate($im, 255, 0, 0);
    
    }
       else   if($color==black)
    {
    $color =  ImageColorAllocate($im, 0, 0, 0);
    }
     imagettftext($im, 20, 0, 100, 200, $color, $font, $text);
    imagejpeg($im,"",100);
        imagedestroy($im);
    
    
    PHP:
    please help i wanna to know how to rename and save this image
    thank you
     
    mirosoft1, Sep 8, 2010 IP
  2. Michellu

    Michellu Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    the second parameter of this function: imagejpeg($im,"",100) is the path and filename of the image you are creating.
    So if you want to save the image as "image1.jpg" in folder "pictures" you will write:
    imagejpeg($im,"pictures/image1.jpg",100);
     
    Michellu, Sep 8, 2010 IP
  3. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    this solution didnot work with me
    it gives me the path of the page
    http://www.mysite.com/image.php
     
    mirosoft1, Sep 8, 2010 IP
  4. Michellu

    Michellu Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Be very careful with the path of the location you are trying to save to. Also make sure that PHP has writing rights for that folder.
    Could you show us the code with the path and filename?
     
    Michellu, Sep 8, 2010 IP
  5. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    i made directory called pic and chmod 777
    the code

    $path=pic/image1.jpg;
    imagejpeg($im,$path,100);
     
    mirosoft1, Sep 8, 2010 IP
  6. Michellu

    Michellu Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Michellu, Sep 8, 2010 IP
  7. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #7
    it gives me the link of the page and when i delete this $path , the image appear normaly
    i donot know why didnot work but of course there are another way to save the image
    i want also to rename the image and save it on the database :( :(
     
    mirosoft1, Sep 8, 2010 IP
  8. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #8
    no one can help????
     
    mirosoft1, Sep 13, 2010 IP