Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,246
    Rep Power
    220

    Get image dpi and other if it's an image


    Hey

    2 questions about images please shed light with your lightsabers.

    1 - I want users to upload image that is 300dpi and 90mmx55mm

    To make sure the file is image, how's this? Potential errors?
    PHP Code:
    if(isset($mediapath))
      {
        if(@
    is_array(getimagesize($mediapath)))
          {
            
    $image true;
          }
        else
          {
            
    $image false;
          }
      } 
    2 - I do this in Jquery modal, upload them to S3 and then when upload I do a bunch of other Jquery and replace a few image src attributes and show the design on screen.

    What would be the best way to check images dpi before I do all that.

    With
    PHP Code:
    $size getimagesize("tpe.png"); 
    I get
    Array ( [0] => 400 [1] => 253 [2] => 3 [3] => width="400" height="253" [bits] => 8 [mime] => image/png )
    That tells me nothing about dpi. That tells me less than nothing.
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    DPI is not a property of an image but of the display medium used to show the image. Such as a monitor or printer. A "dot" is an arbitrary thing representing the smallest piece of an image (eg, pixel on a monitor, ink dot on a printer) and DPI is how many of those you can squeeze into an inch.

    300dpi is about 11.81px/mm ("pixel" not on a screen but as a coordinate on an image) so 90x55mm is ~1063x650px. Don't require that exact dimension, of course - set up an acceptable range on both dimensions.
    Last edited by requinix; July 14th, 2017 at 06:56 AM.
  4. #3
  5. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,246
    Rep Power
    220
    Hey. Quick one, related to this:

    I want the user to upload images that I am gonna print on sharetapes later (like business card kinda thing).

    I want to:

    1 - Maintain the ratio

    2 - Make sure it's 300dpi

    3 - Do not stretch it at all.

    4 - If bigger than 1063*650, resize down.

    What would be the best logic to resize it using Codeigniters logic? I can't come up with a simple logic.

    Something like this without me having to assign different if/else etc

    PHP Code:
    $config2['source_image'] = $this->upload->upload_path $this->upload->file_name;
    $config2['new_image'] = $this->upload->upload_path $this->upload->file_name;
    $config2['image_library'] = 'gd2';
    $config2['quality'] = "100%";
    $config2['maintain_ratio'] = TRUE;
    $size getimagesize($config2['source_image']);
    if (
    $size[0] > 1063 && $size[1] > 650
        {
            
    $config2['height'] = 650;

        }
    $this->load->library('image_lib'$config2
    Thanks
    Last edited by English Breakfast Tea; October 23rd, 2017 at 08:22 AM.
  6. #4
  7. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,110
    Rep Power
    4103
    If you want it to be exactly 1063x650 then I'd just check that the image is not already that and if not, resize it to that.
    Code:
    $size = getimagesize($config2['source_image']); 
    if ($size[0] != 1063 && $size[1] != 650){
        $config2['source_image'] = $this->upload->upload_path . $this->upload->file_name; 
        $config2['new_image'] = $this->upload->upload_path . $this->upload->file_name; 
        $config2['image_library'] = 'gd2'; 
        $config2['quality'] = "100%"; 
        $config2['maintain_ratio'] = TRUE; 
        $config2['width'] = 1063;
        $config2['height'] = 650;
        $this->load->library('image_lib', $config2) 
    }
    If you maintain the aspect ratio though then even after the resize one of the sides may be longer or shorter than your desired size. If you really need it exactly at those dimensions then you'd need to resize it such that the longest side fits, then pad out the shorter side til it matches your desired size.
    Last edited by kicken; October 23rd, 2017 at 09:25 AM.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  8. #5
  9. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,246
    Rep Power
    220
    How about "not stretching the image if it's smaller than 1063x650"?

    How can I make sure such images don't get stretched?
    Last edited by English Breakfast Tea; October 24th, 2017 at 08:27 AM.
  10. #6
  11. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,246
    Rep Power
    220
    The thing is “we need to maintain a 1065 by 650 pixel density”.

    When you upload an image you want it to fill that area but it might not be the right dimensions/ aspect ratio. So if it's too small we put it bottom right. If it's too big by one dimension we resize to fit it or potentially we don't have to if we can get a drag working.

    If both dimensions are too big we resize the smallest dimension to fit the space. All this means that they get their image fitting in the area better
  12. #7
  13. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    Quoting something? According to that they won't do anything with small images but put them in a corner. So no stretching.
  14. #8
  15. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,246
    Rep Power
    220
    Yes but they also say
    1500 x 670, resize to: ??? by 650
    1000 x 750 resize to: ??? by 650
    Which doesnt make sense to me.Regardless of width, they wanna resize to height 650.

    I wanna know what their requirements are but looks like something's missing.
  16. #9
  17. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
  18. #10
  19. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,246
    Rep Power
    220
    The client asking for this.

    Remember what I messaged you this morning? The ajax upload.

    They want the uploaded image to be resized, keep the dpi 300 and do all the things I posted above.

    I don't know exactly what they want and we have a hard time communicating.

    I thought if I post here it might be clear for you.

    How can I clarify the requirements?


    :0
  20. #11
  21. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    Examples of input and output images, with an explanation of why?

    So far all I have gathered from this is that images with a dimension larger than 1065w or 650h are resized so one dimension matches and the other is longer, then the extra is cropped out. Smaller images are not resized.

    Oh. And you cannot do anything about DPI. I thought we went over this.
  22. #12
  23. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,246
    Rep Power
    220
    Yes. I will continue on this and write back tomorrow when I know more.

    Thanks again
  24. #13
  25. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,246
    Rep Power
    220
    Yes so far everything you mentioned is correct.

    I think next we should check if image smaller than the size specified, we don't resize. What else can you see is missing?

    Ah and here's the code so far:

    PHP Code:
    private function uploadFile($inputFile="file"$allowed_type="gif|jpg|png"$resize_image TRUE){
            
    //Codeigniter upload
            
    $config['upload_path'] = $this->upload_path;
            
    $config['allowed_types'] = $allowed_type;
            
    $config['encrypt_name'] = TRUE;
            
    $config['max_size'] = $this->maxSize;
            
    $config['max_width'] = 0;
            
    $config['max_height'] = 0;
            
    $this->upload->initialize($config);
            if (!
    $this->upload->do_upload($inputFile)) {
                return 
    false;
            } else {
                if (
    $resize_image
                    {
                            
    $config2['source_image'] = $this->upload->upload_path $this->upload->file_name
                            
    $size getimagesize($config2['source_image']); 
                            
    $config2['new_image'] = $this->upload->upload_path $this->upload->file_name
                            
    $config2['image_library'] = 'gd2'
                            
    $config2['quality'] = "100%"
                            
    $config2['maintain_ratio'] = TRUE
                            
    $config2['width'] = 1063;
                            
    $config2['height'] = 650;
                            
    $this->load->library('image_lib'$config2);                        
                            if (!
    $this->image_lib->resize())
                                {
                                    
    //echo $this->image_lib->display_errors();
                                
    }
                            else 
                                {
                                    
    //echo "Resized successfully!";
                                

                            return 
    $this->upload->data();          
                       
                    
    //

                            
                
    }
                
                
            }
        } 
  26. #14
  27. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,436
    Rep Power
    9645
    Make sure the resize() does it as desired: resize to the smaller dimension, crop the extra from the larger dimension.
  28. #15
  29. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,246
    Rep Power
    220
    hey out of curiosity,

    How can I resize to a specific width or height by assigning only width or height and keep the other aspct (width or height) set automatcially?

    For example:

    PHP Code:

    $config2
    ['source_image'] = $this->upload->upload_path $this->upload->file_name
    $size getimagesize($config2['source_image']); 
    $config2['new_image'] = $this->upload->upload_path $this->upload->file_name
    $config2['image_library'] = 'gd2'
    $config2['quality'] = "100%"
    $config2['maintain_ratio'] = TRUE
    $config2['width'] = 1063;
    $this->load->library('image_lib'$config2);                        
    $this->image_lib->resize(); 
    or


    PHP Code:

    $config2
    ['source_image'] = $this->upload->upload_path $this->upload->file_name
    $size getimagesize($config2['source_image']); 
    $config2['new_image'] = $this->upload->upload_path $this->upload->file_name
    $config2['image_library'] = 'gd2'
    $config2['quality'] = "100%"
    $config2['maintain_ratio'] = TRUE
    $config2['height'] = 650;
    $this->load->library('image_lib'$config2);                        
    $this->image_lib->resize(); 
    This doesnt seem to resize.

    Thanks
    Last edited by English Breakfast Tea; October 25th, 2017 at 09:46 AM.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo