sowna Posted November 9, 2011 Share Posted November 9, 2011 Hi, i want to resize the image inside html content. If the image width above 600, i have to set to 600 as default width for that image. Example, $string = '<p>Also from the wonderful Tank Theory line is this nice Comrade t-shirt. She’s not all that innocent, not that she really looks it, but if you inspect the shirt closer you’ll see she is hiding something on the back. The shirt is now available in red with black wterbased print, and gold foil accents.</p> <p><a title="Tank Theory Comrade" href="http://www.tanktheory.com/store/standard-t-shirts/product/comrade/" target="_blank"><img class="alignnone size-full wp-image-2642" title="m_509_tank_theory_red" src="http://www.birdfight.com/blogfiles/wp-content/uploads/2009/02/m_509_tank_theory_red.jpg" alt="m_509_tank_theory_red" style="height: 400px; width:800px;"></a></p>'; Please help me... Quote Link to comment https://forums.phpfreaks.com/topic/250759-resize-image-inside-html-content/ Share on other sites More sharing options...
joe92 Posted November 9, 2011 Share Posted November 9, 2011 Why do you need regex for this? You could just apply a max-width style to the image: style="max-width:600px;" Quote Link to comment https://forums.phpfreaks.com/topic/250759-resize-image-inside-html-content/#findComment-1286534 Share on other sites More sharing options...
sowna Posted November 9, 2011 Author Share Posted November 9, 2011 No...if you apply like that then it will set width 600 to all images... I don't want like that... I want to resize those image width more than 600. Quote Link to comment https://forums.phpfreaks.com/topic/250759-resize-image-inside-html-content/#findComment-1286537 Share on other sites More sharing options...
joe92 Posted November 9, 2011 Share Posted November 9, 2011 That's what it will do. It will say that the maximum width can only be 600px. Anything under 600px will be left as is, and anything over 600px will be resized to be 600px. Quote Link to comment https://forums.phpfreaks.com/topic/250759-resize-image-inside-html-content/#findComment-1286544 Share on other sites More sharing options...
AyKay47 Posted November 9, 2011 Share Posted November 9, 2011 No...if you apply like that then it will set width 600 to all images... I don't want like that... I want to resize those image width more than 600. what joe92 provided will do exactly what you are saying that you will want, any image that is less then a width of 600px will not be affected by the CSS, and image bigger than 600px will be shrunk to a width of 600px. Quote Link to comment https://forums.phpfreaks.com/topic/250759-resize-image-inside-html-content/#findComment-1286549 Share on other sites More sharing options...
sowna Posted November 9, 2011 Author Share Posted November 9, 2011 Yeah its working when i apply the max width. but the image get shrink and not looks so good. Thats why i would like to Resize image. If i resize image, then it wont loss its clarity. Hope you understand now... Quote Link to comment https://forums.phpfreaks.com/topic/250759-resize-image-inside-html-content/#findComment-1286557 Share on other sites More sharing options...
AyKay47 Posted November 9, 2011 Share Posted November 9, 2011 you want to create a thumbnail then, I recommend you use GD http://us2.php.net/manual/en/book.image.php Quote Link to comment https://forums.phpfreaks.com/topic/250759-resize-image-inside-html-content/#findComment-1286562 Share on other sites More sharing options...
sowna Posted November 9, 2011 Author Share Posted November 9, 2011 while loading itself i have to resize the image. can you please tell me how to get the width, height of the image and to replace the custom width and height. From: <img src="test.jpg" style="width:1024px; height:600px;" title="test" alt="test"> To: <img src="test.jpg" style="width:600px; height:400px;" title="test" alt="test"> plz.... Quote Link to comment https://forums.phpfreaks.com/topic/250759-resize-image-inside-html-content/#findComment-1286625 Share on other sites More sharing options...
AyKay47 Posted November 9, 2011 Share Posted November 9, 2011 these things are mentioned in the link I provided.. there is no easy answer here, you must understand the basics of GD.. read into the documentation that I linked you to Quote Link to comment https://forums.phpfreaks.com/topic/250759-resize-image-inside-html-content/#findComment-1286629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.