2

I want to know is there any inbuilt function in php through which I can display an image greater than the size stored in database(i.e. greater than the original size).

I know it can be done using the HTML/CSS properties height and width but I want it done through php only.

I tried imagecreatefromjpeg($filename); but it takes file or directory name in place of $filename and my image is in a database.

Here is a part of my code:

    while( $result=mysqli_fetch_array($runquery))
    {
        echo'<img src="data:image/jpeg;base64,'base64_encode($result['image']).'"/>';
    }
secelite
  • 1,353
  • 1
  • 11
  • 19
user3151681
  • 45
  • 11
  • Why are you saving image in database (base64 encoded?) and not only reference to this file on file system? – Justinas Aug 18 '14 at 10:07
  • Do not store images in your DB http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay – secelite Aug 18 '14 at 10:09
  • @justinas yes i can store it in file on file system but in case if i am storing it in database....can i get a possible solution and will imagecreatefromjpeg($filename); work in that case – user3151681 Aug 18 '14 at 10:16

2 Answers2

2

Load your image with imagecreatefromstring. Then resize it with imagecopyresized.

Also I would suggest you to only save the paths to your image in the database.

secelite
  • 1,353
  • 1
  • 11
  • 19
  • thanks for your valuable comment ....some how it is not working in my case .... i think it is better if i d0 some serious editing work and save my images in file system first .......thanks again for the valuable link.... – user3151681 Aug 18 '14 at 11:17
  • can you please clarify which data type to use for storing image location in database....actually '\' is omitted from image location value by MySQL which is creating problem – user3151681 Aug 18 '14 at 17:41
  • got it .... actually i have to use '\' two times .i.e. images\\1.jpg earlier i was writing images\1.jpg...... – user3151681 Aug 18 '14 at 18:10
  • @user3151681 yes, you have to escape the backslashes. Look at `addslashes` http://php.net/manual/en/function.addslashes.php – secelite Aug 19 '14 at 07:04
  • can you help with these question http://stackoverflow.com/questions/25388964/image-is-not-getting-displayed-on-the-web-page-instead-the-text-loading-is?noredirect=1#comment39598062_25388964 – user3151681 Aug 19 '14 at 17:52
1

Get Imagick ready and call following function

bool Imagick::setImageExtent ( int $columns , int $rows )

Reference: Imagick::setImageExtent

ydoow
  • 2,969
  • 4
  • 24
  • 40
  • 1
    ImageMagick is not installed on every system, so it may not fit op's needs for an inbuilt function – secelite Aug 18 '14 at 10:17