473,624 Members | 2,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to output a JPG/JPEG image in html with low quality for faster browsing?

1 New Member
I have like 50000 images on my server, and each image is about 7mb of size. I made a gallery script based on the famous html code for displaying image :
<img src="image.jpg" width="200" height="150">
Even after setting the width and the height, the image is till taking time to display, because it's always download the 7mb sized image.

So, I'm here to ask you, Experts, if there is any way to display these images in a form of thumbnail with a lower quality, so it can be displayed quickly. I would like to do that without creating thumbnails of those 50000 images.

I appreciate any help or idea from your behalf.
I hope you all find my question interesting and i hope that we can find out a solution for this problem.
Thank you very much.
Dec 3 '11 #1
5 3876
drhowarddrfine
7,435 Recognized Expert Expert
No. The only thing you can do is have images resized smaller.
Dec 3 '11 #2
omerbutt
638 Contributor
you can try this simple script if you have the jnow how of GD library

Using Imagecopyresize d ()
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  // The file you are resizing 
  3.  $file = 'your.jpg'; 
  4.  
  5.  //This will set our output to 45% of the original size 
  6.  $size = 0.45; 
  7.  
  8.  // This sets it to a .jpg, but you can change this to png or gif 
  9.  header('Content-type: image/jpeg'); 
  10.  
  11.  // Setting the resize parameters
  12.  list($width, $height) = getimagesize($file); 
  13.  $modwidth = $width * $size; 
  14.  $modheight = $height * $size; 
  15.  
  16.  // Creating the Canvas 
  17.  $tn= imagecreatetruecolor($modwidth, $modheight); 
  18.  $source = imagecreatefromjpeg($file); 
  19.  
  20.  // Resizing our image to fit the canvas 
  21.  imagecopyresized($tn, $source, 0, 0, 0, 0, $modwidth, $modheight, $width, $height); 
  22.  
  23.  // Outputs a jpg image, you could change this to gif or png if needed 
  24.  imagejpeg($tn); 
  25.  ?> 
  26.  
Using Imagecopyresamp led ()
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  // The file you are resizing 
  3.  $file = 'yourfile.jpg'; 
  4.  
  5.  //This will set our output to 45% of the original size 
  6.  $size = 0.45; 
  7.  
  8.  // This sets it to a .jpg, but you can change this to png or gif 
  9.  header('Content-type: image/jpeg'); 
  10.  
  11.  // Setting the resize parameters 
  12.  list($width, $height) = getimagesize($file); 
  13.  $modwidth = $width * $size; 
  14.  $modheight = $height * $size; 
  15.  
  16.  // Resizing the Image 
  17.  $tn = imagecreatetruecolor($modwidth, $modheight); 
  18.  $image = imagecreatefromjpeg($file); 
  19.  imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height); 
  20.  
  21.  // Outputting a .jpg, you can make this gif or png if you want 
  22.  //notice we set the quality (third value) to 100 
  23.  imagejpeg($tn, null, 100); 
  24.  ?> 
  25.  
optionally you an use phpthumb also see here
regards,
Omer Aslam
Dec 4 '11 #3
seoquake
1 New Member
I still think the most optimal way is to generate thumbnails right after they're uploaded. Why? Because if you generate thumbnails on the fly, all the 7mb still have to be loaded into memory and considerable amount of processing has to be done each time a user views an image.
Dec 5 '11 #4
omerbutt
638 Contributor
yes seoquake i agree ,
that is why i have added a link to phpthumb in the end , whatever h likes , choices he have.
regards,
Omer Aslam
Dec 5 '11 #5
nilswap
4 New Member
Better way is that u can convert all these images in .png format.Because, Noone is going to use .jpg or .jpeg formats.
Oct 24 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2660
by: Ming | last post by:
Hi All, I want to write a PHP webpage which allows people to upload images (no matter what formats) to me and at the same time converts any non-jpeg image to JPEG. Here's what I have: $FileDest = "/uploads/1.gif"; if (!move_uploaded_file($_FILES, $FileDest)):
2
17042
by: Lucas Cowald | last post by:
Hi, Using ASP and VBScript. How to convert JPEG image into a binary data? Is it possible with a command from ASP / VBScript without having to put it into a database first? I want to take the JPEG image from a folder, convert it into a binary data, and stream it to the browser. How can I do it? Can you show a short code? Thank you for your help.
2
4161
by: Onwuka Emeka | last post by:
is there a way to reduce or modify the color depth of a jpeg image, i currently need to programatically change the color depth of a jpeg image from 24bits to 8bits. any help would be appreciated
1
1964
by: spgedwards | last post by:
I am trying to run a basic script that displays an existing jpeg image and writes some text over it. Sounds simple, but I cannot seem to be able to colour the font correctly. In the example below it should be black but it comes out orange. In fact, even if I change the colour to 0, 0, 255 it's orange. I've read in the PHP documentation (the user contributed notes) that there are issues with jpeg font colouring. But I've not seen any...
6
3397
by: RaulAbHK | last post by:
Dear all, I guess this is a basic question with an easy answer but I am a beginner and I would much apreciate your feedbacks. Let's say I have a library with some functionality to perform some image processing on jpeg images. One of functions in the library is similar to this: myfunction_effect (&out_instance, &mysettings, I8 *buf_in, I32
0
1570
by: nma | last post by:
Hiya, Can anyone help me in this..i'm stuck I have created a table in SQL server that contain field name (shotSelectedKeyfrm -int type, and imgSelectedKeyfrm-varchar(255) type) like below: Column1 Column2 32 340
0
1723
by: =?Utf-8?B?TWFyazEyMw==?= | last post by:
I have two pieces of VB.NET code below: a) Sends an email b) Returns a programmatically created jpeg image to a webpage. How can I embed the programmatically created jpeg into an HTML formatted email (without saving the jpeg to disk)? Code a) ======
1
2505
by: Puneeth kamath | last post by:
I am working on pdf to xml conversion. I achieved pdf to text by using pdf clown samples. Now I am able to extract the pdf to text and image as well. But the problem is,the saved image is blurry. else if (content is it.stefanochizzolini.clown.documents.contents.objects.GraphicsObject) { /*============================================================================= * TO...
2
6055
by: santhanalakshmi | last post by:
Hi, I am running Apache and the Active Perl. In Apache, CGI folder, i had one JPEG image. I wants to display this JPEG image in my browser as the header. use CGI qw(:all); print "Content-type: text/html\n\n"; print "<body bgcolor="FFFF">; print "<img src=\cgi-bin\header.jpg>"; print "</body>;
0
2051
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I've got an image that I want to load, it's a JPEG image and it has a solid background of color rgb(11, 12, 14). I want to make the background transparent and outpt the image as a PNG. I've tried this code: header("Content-Type: image/png"); $im = imagecreatefromjpeg("http://www.bungie.net/stats/reach/nightmap.ashx"); $bg = imagecolorallocate($im, 11, 12, 14); imagesavealpha($im, true); imagecolortransparent($im, $bg); imagepng($im); ...
0
8233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.