PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label gif. Show all posts
Showing posts with label gif. Show all posts

Monday, July 18, 2022

[FIXED] How can I take an existing animated GIF and make it play only once?

 July 18, 2022     animated-gif, gif, python, python-3.x     No comments   

Issue

I'm relatively new to Python. I have a large group of animated gif files which I need to change from looping forever, to playing only once. Since I already know how to perform operations on multiple files using Python I'm halfway there.

So, is there a way to read the gif, change its setting and then save it?

I'm using python 3 FYI.

EDIT: Umm, if I did something wrong, please respond to let me know. Downvoting me into oblivion doesn't help me.


Solution

Check out Pillow and the documentation in its parent library, PIL. Whether a GIF repeats is configured through the Image.info['loop'] property.



Answered By - lyschoening
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to use gif image inside html5 canvas?

 July 18, 2022     gif, html5-canvas     No comments   

Issue

I've been searching all day to use gif image inside html5 canvas can't find a useful article in it,is there any way I could use gif image inside canvas. I'm in position to use a gif image inside a canvas but it doesn't changes it loads loads the first frame only and how to play the gif image completely or is there any way I could use gif formatted image inside a canvas.


Solution

Quote from jsgif: A GIF player in JavaScript

Unfortunately, the DOM doesn't expose individual frames of a GIF, so this is done by downloading the GIF (with XMLHttpRequest), parsing it, and drawing it on a .

Maybe you would take a look in the jsgif source code to find some ideas



Answered By - alessandro
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I cascade start multiple gifs?

 July 18, 2022     gif, html, javascript, jquery     No comments   

Issue

I have a gif of a candle with an animated flame. My webpage will show a few of these gifs in a row. It would be much more realistic if all the gifs didn't start at once after the page loads (otherwise I get a line of 'synchronised' candles).

I can create multiple gifs with different flame animations and then randomise which ones get shown but this will take extra bandwidth and will add an extra level of complexity.

Is there a way to maybe cascade start the gifs? i.e. start each one after a random amount of time in order that they are out of synch and look a bit more realistic?

Maybe using jquery? Or simple javascript?

Many thanks


Solution

You can't do that. If you place the same image on multiple places, it's going to always look the same. You could edit the image and change the order of the frames within the gif, save and repeat this a few times, and then load the gifs, but this will only work if the images are already loaded (cached) on your browser. If this is the first time you load the page, it could just happen that an image will be loaded exactly when another image started from the first frame of the loaded image, so it will look as if they are in sync.

You could load the images using setTimeout but this will have the same problem as described above when the user first enters your page. You can delay the request for loading the file, but you have no control of the speed in which the file will be downloaded and therefor no control on when exactly the first frame will start playing.

If I were you, I'd try creating a big sprite of different images, each starting the animation from a different frame. There will be only one request and all animations will play together, making sure frames are never in sync. When displaying the images on the site, make sure to properly show only the part you want for each image. This will give you the effect of flames burning at random times.



Answered By - Narxx
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to check if a particular file already exists by using an uploaded file to find a match in PHP

 July 18, 2022     file-upload, gif, match, pattern-matching, php     No comments   

Issue

giphy.com, during an upload, somehow recognizes if a particular GIF animation has already been uploaded to their servers. and I was wondering how I can replicate that using PHP in a very efficient (low-server intensive) manner?

The only way I can think of doing this is by looping between all the files on my server (which I would think would be a highly server intensive task) and trying to find a match (and by match, I don't mean filename; I mean if the exact same gif was uploaded (the exact file regardless of the filename)).

But I'm not too sure of what particular PHP functions I'd have to use.


Solution

Use a database. At each upload you calculate a md5 hash of the file ( using md5_file ) and you store that in the database. Looking up the database to see if the hash already exists will be very fast.



Answered By - Lorenz Meyer
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How are multiple images combined into a GIF?

 July 18, 2022     gif     No comments   

Issue

How are multiple images combined into a GIF? Is it possible to break them up once they are combined?


Solution

Yes, they are extractable. Wikipedia gives you a hint about the technology behind the fileformat. The GIMP is a nice way to edit and separate each frame (as layer for example)



Answered By - ExploWare
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to reduce the initial time to show loader?

 July 18, 2022     gif, ios7, loader, nstimer, xcode5     No comments   

Issue

I am implementing loader in button action , but when i click on button it takes 3 to 5 sec to start loading. i am using two controller to implement loader- UIImage+animatedGIF.h to use gif image and MBProgressHUD.h to implement progress time. i don't know how to reduce the initial time that takes to start loader. I am using this code to implement loader-

NSURL *url = [[NSBundle mainBundle] URLForResource:@"loadingg" withExtension:@"gif"];

    self.loader.image = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];


    float progress = 0.0f;

    while (progress < 1.0f) {



        progress += 0.01f;

       // HUD.progress = progress;

        usleep(50000);


    }

    [NSTimer scheduledTimerWithTimeInterval:progress target:self selector:@selector(abcd) userInfo:nil repeats:NO];     

Solution

I must assume that usleep(50000) is not on the main thread.

If it is, there is your 5 secs delay. Sleeping the main thread does just that: wait. The right approach is an asynchronous load.

Read @bbum recommendation for when it's appropriate to invoke usleep: what is the difference among sleep() , usleep() & [NSThread sleepForTimeInterval:]?



Answered By - SwiftArchitect
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to avoid malloc while using CGImageDestinationFinalize

 July 18, 2022     animated-gif, cgimage, gif, ios, objective-c     No comments   

Issue

I am trying to programmatically create GIF in iOS, using the following stack's question:

Create and and export an animated gif via iOS?

My code looks like this:

 // File Parameters
const void *keys[] =   { kCGImagePropertyGIFLoopCount };
const void *values[] = { (CFNumberRef) 0 };

CFDictionaryRef params          = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
const void *keys2[] =   { kCGImagePropertyGIFDictionary };
const void *values2[] = { (CFDictionaryRef) params  };

CFDictionaryRef fileProperties  = CFDictionaryCreate(NULL, keys2 , values2, 1, NULL, NULL);

// URL to the documents directory
NSURL *documentsDirectoryURL  = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
NSURL *fileURL                = [documentsDirectoryURL URLByAppendingPathComponent:fileName];

// Object that writes GIF to the specified URL
CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)fileURL, kUTTypeGIF, [arrayOfAllFrames count], NULL);
CGImageDestinationSetProperties(destination, fileProperties);

for (NSUInteger i = 0; i < [arrayOfAllFrames count]; i++) {
    @autoreleasepool {
        float delayTime = [[gifFramesDuration objectAtIndex:i] floatValue]; 
        NSDictionary *frameProperties = @{
                                          (__bridge id)kCGImagePropertyGIFDictionary: @{
                                                  (__bridge id)kCGImagePropertyGIFDelayTime: [NSNumber numberWithFloat:delayTime] // a float (not double!) in seconds, rounded to centiseconds in the GIF data
                                                  }
                                          };

        UIImage *myImage = [arrayOfAllFrames objectAtIndex:i];
        CGImageDestinationAddImage(destination, myImage.CGImage, (__bridge CFDictionaryRef)frameProperties);
    }
}
if (!CGImageDestinationFinalize(destination)) {
    NSLog(@"failed to finalize image destination");
}
CFRelease(destination);
CFRelease(fileProperties);
CFRelease(params);

However once I try to add around 240 frames to the GIF file, debugger throws the following error once the CGImageDestinationFinalize gets called:

(923,0xb0115000) malloc: *** error for object 0xd1e7204: incorrect checksum for freed object - object was probably modified after being freed.

Could you please provide me with some workaround, or with a suggestion on how to avoid malloc?


Solution

First of all, try debugging your app using Instruments. You probably will notice that the problem is caused by the method: Generatefromrgbimagewu

I have been wondering whether the cause was in my threads implementation, but it turns out, that once you have that kind of error, you should focus on resizing the Image.

Once the image had been resized, the code published above, will generate your own GIF.



Answered By - Michael
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How would you upload an image URL to an external website which generates a new URL for it and retrieve the newly generated url in rails?

 July 18, 2022     gif, ruby, ruby-on-rails, upload, url     No comments   

Issue

I am creating a website which allows users to post links to gif images stored externally. Unfortunately gifs are terribly expensive and luckily I have found the following website which compresses them quite radically: http://gfycat.com/

Currently my app stores the url to the linked image (as of yet it is uncompressed and without the use of gfycat)

What I would like to do is to take the url that the user posts, use it to compress the gif via gfycat.com and then store the newly generated url (pointing to the compressed image) in my database.

How would I do this?

Sorry for the long explanation btw


Solution

Just took a look at gfycat.com, seems like they do have an accessible webservice at http://gfycat.com/fetch/:url

If this is the case, and you already have the URL you can very easily grab the 'minified' version of the gif by grabbing the URL and saving the file.

So, I would probably do something like this:

  • Install carrierwave or another image upload gem of your choice

In the case you used the above gem...

assuming Cat is your model, and you have an uploader attached to it named gif_photo, and also assuming the original 'gif' url is stored as original_gif_url

You can do something like the following (assuming @cat is some instance of the cat model):

@cat.update_attribute(:remote_gif_photo_url, "http://gfycat.com/fetch/#{@cat.original_gif_url}")

as simple as that :)... to get back at the gif, you can simply call @cat.gif_photo_url

(again, assumptions for code above are using carrierwave syntax, but can easily be done with any of its alternatives.)



Answered By - derekyau
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to keep animated gifs animated while scrolling on iOS devices?

 July 18, 2022     css, gif, image-processing, ios, scroll     No comments   

Issue

I know this has been asked before but I'm still not convinced there's not a workaround. The reason I'm not convinced is because I managed to keep those gifs animated on a website of mine by accident. I posted this in the chat here and with help from @CarrieKendall came up with this fiddle.

This is obviously not a proper solution so I wanted to post it here for you geniuses to pick apart and try to help me figure out how I can fix this problem (in a way that preferably is not too resource heavy)?

UPDATE:

Ok, so I tinkered a bit more with the jsfiddle and came up with this:

HTML

<img class="link" src="http://i.imgur.com/jsm0x2c.gif">
<img class="link" src="http://i.imgur.com/jsm0x2c.gif">
<img class="link" src="http://i.imgur.com/jsm0x2c.gif">

CSS

@-webkit-keyframes WIGGLE {
  0%   { -webkit-transform: translate(0px, 0px); }
  100%   { -webkit-transform: translate(0px, 0px); }
}

keyframes WIGGLE {
  0%   { -webkit-transform: translate(0px, 0px); }
  100%   { -webkit-transform: translate(0px, 0px); }
}

.link{
  -webkit-animation: WIGGLE 1ms; 
          animation: WIGGLE 1ms;
}

It's strange, but it works. An animation that does absolutely nothing. Oh and I tried replacing translate with something like scale but that didn't do the trick. This is the "purest" form of this weird bug/solution.

That said though, I'm not quite satisfied yet. I'd love it if someone more knowledgeable than me could have a look at this and try to figure what is REALLY going on that makes this workaround... work. Hopefully there's something in here that can be used, albeit in a more elegant way.

Also, I have no idea how resource intensive something like the above workaround would be, so if someone could help me measure that that'd be awesome.


Solution

The same restrictions don't occur on a desktop browser. This is specific to the implementation of scrolling that Apple has on their mobile device. It's a hold-over from their older mobile devices to make sure scrolling stays smooth, as earlier iPhones made judicious use of accelerated rendering throughout their OS.

Triggering hardware acceleration changes the render path of the page. In a non-accelerated page, the browser renders directly to the onscreen texture. When scrolling, all other execution is stopped, because the smooth scroll renderer takes control of rendering. This is not limited to just GIFs. If javascript would have changed the page content, it would also not show until the page finished scrolling.
In an accelerated page, the accelerated objects are actually sent to the compositor. The compositor puts all the layers of objects in the right place, and then creates a composite texture to put on the screen. Scrolling is actually part of the compositor's job, and since the compositor is in charge of rendering from end-to-end, animations will continue.

Unfortunately, due to the design of Apple's system compositor, there is really no 'right' way. In fact, as Apple has been making updates to iOS, there have been changes to what is hardware accelerated, and what isn't. For example, in iOS6, preserve3d no longer triggered acceleration. Supposedly,
-webkit-backface-visibility: hidden;
-webkit-perspective: 1000;
should still work. In your case, I believe it works because you are using keyframes.

In terms of performance/resource impact, your page won't use any more resources than any other accelerated page.



Answered By - joe
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to convert a BufferedImage to gif in java

 July 18, 2022     encoding, gif, java     No comments   

Issue

I want to convert a BufferedImage to gif. I already converted BufferedImage to jpeg with a function and the output was Byte[] so I could send it over the inet with a socket connection.

I need a gif encode function similiar to this jpeg encode function:

public static byte[] getImageAsJPEG(BufferedImage image) throws ImageFormatException, IOException {
    ByteArrayOutputStream output = new ByteArrayOutputStream();

    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
    param.setQuality(0.9f, false);
    encoder.setJPEGEncodeParam(param);
    encoder.encode(image);

    return output.toByteArray();
}

Solution

Use:

ImageIO.write(image, "GIF", output);

As in:

public static byte[] getImageAsGIF(BufferedImage image) throws ImageFormatException, IOException {
    ByteArrayOutputStream output = new ByteArrayOutputStream();

    ImageIO.write(image, "GIF", output);

    return output.toByteArray();
}


Answered By - Erwin Bolwidt
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to terminate a JFrame after a specific amount of time?

 July 18, 2022     awt, gif, java, jframe, swing     No comments   

Issue

I want a JFrame to display a gif, which is my loading screen and then automatically terminate. I am OK with either terminating it after a particular time period or after it completes displaying the gif. Is there any way to do this?


Solution

to display a gif, which is my loading screen and then automatically terminate.

Sounds like you might want a splash screen.

See the section in the Swing tutorial on How to Create a Splash Screen for more information and a working example.



Answered By - camickr
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to create an animated GIF using FFMPEG with an interval?

 July 18, 2022     animated-gif, ffmpeg, gif     No comments   

Issue

Hello fellow overflowers,

A brief overview of what I'm trying to accomplish; I have a site that will accept video uploads, uploads get converted into the mp4 format to be uniformed and playable on the web using one of the many available players. That part is all fine and dandy.

The problem now is I want to show the user a short scaled preview (animated gif) of the video before they click to play it. The code I'm working with now is

ffmpeg -i test.mp4 -vf scale=150:-1 -t 10 -r 1 test.gif

Which works for creating a scaled animated gif with a fixed width of 150px at a rate of 1 frame per second but its only an animation of the first 10 seconds of the video. I'm trying to do something that spreads out the frame gap to cover the whole video length but create an animated gift that's no more then 10 seconds long.

For example say I have a video that's 30 seconds I want the gif to be 10 seconds long but cover frames of the entire 30 seconds so it might start at frame 3 or 3 seconds in and create a frame in the gif, then at 6 seconds in the video create another frame, then 9 seconds in another, and so forth where the final outcome is

    example video 30 seconds long          example video 1 minute 45 second long 

video position - gif frame/per second      video position - gif frame/per second
      00:03:00   1                               00:10:50   1
      00:06:00   2                               00:21:00   2
      00:09:00   3                               00:31:50   3
      00:12:00   4                               00:42:00   4
      00:15:00   5                               00:52:50   5
      00:18:00   6                               01:03:00   6
      00:21:00   7                               01:13:50   7
      00:24:00   8                               01:24:00   8
      00:27:00   9                               01:34:50   9
      00:30:00   10                              01:45:00   10

  3 second interval between frames         10.5 second interval between frames

Where you end up with an animated gif that's 10 seconds long showing a preview of the entire video no matter the length of it. Which basically just boils down to video length / 10 (length of desired animated gif) = interval to use between frames but I don't know how I can use that data to accomplish my problem...

So does anyone have an idea or suggestion on how this can be accomplished with relative ease? I can probably do it by calculating the length through code and running a command to extract each individual frame from the video that's needed then generate a gif from the images but I'd like to be able to do it all with just one command. Thanks.


Solution

So I ended up just doing this by code having found this script (http://www.alberton.info/video_preview_as_animated_gif_with_ffmpeg_and_spl.html#.UxnU_IXYNyI) which made it easy where you can simply specify the position in the video by percentage on the frame to extract along with the interval between frames I can accomplish my problem above using the following.

// where ffmpeg is located, such as /usr/sbin/ffmpeg
$ffmpeg = '/usr/bin/ffmpeg';

// the input video file
$video = 'sample.avi';

// extract one frame at 10% of the length, one at 20% and so on
$frames = array('10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', '100%');

// set the delay between frames in the output GIF in ms (60 = 1 min)
$joiner = new Thumbnail_Joiner(60);

// loop through the extracted frames and add them to the joiner object specifying 
// the max width/height to make the thumb based on the dimensions of the video
foreach (new Thumbnail_Extractor($video, $frames, '150x150', $ffmpeg) as $key => $frame) {
    $joiner->add($frame);
}

$joiner->save('sample.gif');

The above will go 10% into the length of the video, grab the frame for the first image of the animated GIF, create a 60ms/1sec delay, go 20% into the length of the video and repeat the process for each percentage specified which results in a video of any length having an animated GIF that's 10 seconds long containing 10 frames within the video at 10% intervals in length that show for 1 second each.



Answered By - Jeff Wilbert
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I embed the new GIFV format on my webpage?

 July 18, 2022     animated-gif, gif, html     No comments   

Issue

Normally I would embed a gif like so.

<img src="http://i.imgur.com/awHPuBp.gifv">

Although I get an error that the image could not be loaded.

I'm just wondering what mark up I will need to use so that I can display the GIFV.

GIFV is created by imgur and more information can be found here.


Solution

I just checked that demo site. It seems that they just convert the video to a webm video (in case of Firefox). Check this file here which comes from the demo: http://i.imgur.com/A61SaA1.webm

So I would say you could also just use the <video> tag to embedd those "gif" files. I just guess that use a feature detection and a video converting logic. No idea what this nonsense should be for.



Answered By - rekire
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I convert a collection of canvases into an animated gif in WinRT?

 July 18, 2022     c#, gif, javascript, windows, windows-runtime     No comments   

Issue

I have a javascript Windows 8 application, and I need to convert a bunch of canvases into an animated gif. Here's what I have so far:

I can convert one canvas to a base64 encoded png like this (in javascript):

var base64png = myCanvas.toDataURL()

I can then convert this encoded image into an array of bytes (in a c# class library):

private byte[] GetBytesFromBase64(string base64)
{
    string data = base64.Split(',')[1]; // get everything after comma
    return Convert.FromBase64String(data);
}

I can then use these bytes to create a gif, and save it on the disk (again, in the c# class library):

public async void ConvertToGif(string image)
    {
        // Note: The following line includes methods not shown in the question, but they work
        IRandomAccessStream stream = await ConvertToRandomAccessStream(
                                           ConvertToMemoryStream(
                                           GetBytesFromBase64(image)));

        var decoder = await BitmapDecoder.CreateAsync(stream);
        var pixels = await decoder.GetPixelDataAsync();

        var file = await KnownFolders.PicturesLibrary.CreateFileAsync("test.gif", CreationCollisionOption.ReplaceExisting);
        var outStream = await file.OpenAsync(FileAccessMode.ReadWrite);

        var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.GifEncoderId, outStream);

        encoder.SetPixelData(
            decoder.BitmapPixelFormat, 
            BitmapAlphaMode.Ignore,
            decoder.PixelWidth, 
            decoder.PixelHeight,
            decoder.DpiX, 
            decoder.DpiY,
            ReplaceTransparentWithWhite(pixels));


        await encoder.FlushAsync();
        outStream.Dispose();
    }

This, however, only saves one canvas as one gif. How do I add frames to the gif? There is a GifEncoder class in the System.Media.Imaging namespace, but it seems to not be included in the WinRT .Net framework. Any help would be appreciated.


Solution

I'd suggest you build it your self as you've already got code to convert a Canvas to a single GIF file. Basically, an animated GIF is just a series of GIF files within a container GIF file. While the specification is a bit wordy, you should find this example from the .NET 1.1 days very useful.

Although the standard file format didn't directly allow animation, through "extensions" animations are allowed. The details are well documented on this Wikipedia page.

The core of what you'll need to do is write out a custom header block for the file, and then the individual streams for each animated GIF frame.



Answered By - WiredPrairie
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How would you resize a image/gif in either CSS or HTML?

 July 18, 2022     css, gif, html, image, resize     No comments   

Issue

How would you resize a image/gif in either CSS or HTML? I want the image to still be proportional and I want the gif to be about the size of the google logo on google.com, how would I do that?

CSS or HTML is fine.


Solution

Now the original google.com logo image is 269 x 95. And we know the original image height and width, 1692x396.

if you want this image to be that exact same size, you'll have utilize the css calc().

Knowing that you're new to the web world I'm gonna try to explain it as hard as I can. calc() stands for calculation. HTML is the content of a webpage, such as text and images, and CSS is the styles, such as color, size, and position.

That will select it. Now get the ration of the width you have to the width you want, so 1692/269, and the same with height.

Now we have everything ready and we write:

image {
  width: calc(1692px / 269);
  width: -moz-calc(1692px / 269);
  height: calc(396px / 95);
  height: -moz-calc(396px / 95);
}

This will stretch the picture to the size you needed. If you were wondering what the -moz- things were, they pretty much say that the same, the only difference is that because calc() is not really supported, it will solve that problem for you.

#logo {
  width: calc(1692px / 269);
  width: -moz-calc(1692px / 269);
  height: calc(396px / 95);
  height: -moz-calc(396px / 95);
}
<image src="https://www.google.com/images/srpr/logo11w.png" id="logo">

Because you don't know much about codeing, you can go to the following pages to learn more:

http://www.w3schools.com/

http://www.codecademy.com/learn

Thank you!

UPDATE

I have forgotten that we were talking only about an image. I confused it with the relative size of the parent, and I screwed up.

Anyways, to make it simple, just do:

image {
  width: 269px;
  height: 95px;
}

And that is it. Forget about everything I said earlier.



Answered By - user4013347
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why is my gif image sent from servlet not animating?

 July 18, 2022     bufferedimage, gif, image, java, javax.imageio     No comments   

Issue

I have this following code in my servlet

 response.setContentType("image/gif");
 String filepath = "PATH//TO//GIF.gif";
 OutputStream out = response.getOutputStream();
 File f = new File(filepath);
 BufferedImage bi = ImageIO.read(f);
 ImageIO.write(bi, "gif", out);
 out.close();

This code is just returning first frame of the image.

How to achieve returning full GIF image ?


Solution

Your GIF does not animate, because you are sending only the first frame to the client. :-)

Actually, you are, because ImageIO.read reads only the first frame (and a BufferedImage can only contain a single frame/image). You are then writing that single frame to the servlet output stream, and the result will not animate (it should be possible to create animating GIFs using ImageIO, but the code to do so will be quite verbose, see How to encode an animated GIF in Java, using ImageWriter and ImageIO? and Creating animated GIF with ImageIO?).

The good news is, the solution is both simple, and will save you CPU cycles. There's no need to involve ImageIO here, if you just want to send an animated GIF that you have stored on disk. The same technique can be used to send any binary content, really.

Instead, simply do:

response.setContentType("image/gif");
String filepath = "PATH//TO//GIF.gif";
OutputStream out = response.getOutputStream();

InputStream in = new FileInputStream(new File(filepath));
try {
    FileUtils.copy(in, out);
finally {
    in.close();
}

out.close();

FileUtils.copy can be implemented as:

public void copy(final InputStream in, final OutputStream out) {
    byte[] buffer = new byte[1024]; 
    int count;

    while ((count = in.read(buffer)) != -1) {
        out.write(buffer, 0, count);
    }

    // Flush out stream, to write any remaining buffered data
    out.flush();
}


Answered By - Harald K
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to grab images from folder and post direct links using javascript

 July 18, 2022     gif, google-chrome-extension, javascript     No comments   

Issue

Quick question: I'm trying to create a chrome extension that has gifs, I would like to grab those gifs from a folder on my server. How can I grab gifs from that folder and post them as gifs dynamically?


Solution

Basic HTML :

<img id="dynamic" src="" alt=""/>

JavaScript :

document.getElementById('dynamic').src = '/image/path.gif';

Jquery :

$('#dynamic').attr('src', '/image/path.gif');


Answered By - Shikkediel
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why is an animated .gif icon not showing in JTable column?

 July 18, 2022     gif, icons, jtable, swing, user-interface     No comments   

Issue

Here is the processing.gif Here is the processing.gif

Here is initial.png Here is initial.png

Here is the output Here is the output

Here is the code. processing.gif is working in other locations such as in the tab of a JTabbedPane. Here in the column of a JTable, it is not showing. Any explanation and solution? processing.gif is a moving icon that indicates that something is loading.

import javax.swing.*;
import javax.swing.table.*;

public class TableIcon extends JFrame
{
    public TableIcon()
    {
        ImageIcon initial = new ImageIcon(getClass().getResource("initial.png"));
        ImageIcon processing = new ImageIcon(getClass().getResource("processing.gif"));


        String[] columnNames = {"Picture", "Description"};
        Object[][] data =
        {
            {initial, "initial"},
            {processing, "processing"}
        };

        DefaultTableModel model = new DefaultTableModel(data, columnNames);
        JTable table = new JTable( model )
        {
            public Class getColumnClass(int column)
            {
                return getValueAt(0, column).getClass();
            }
        };
        table.setPreferredScrollableViewportSize(table.getPreferredSize());

        JScrollPane scrollPane = new JScrollPane( table );
        getContentPane().add( scrollPane );
    }

    public static void main(String[] args)
    {
        TableIcon frame = new TableIcon();
        frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
        frame.pack();
        frame.setVisible(true);
    }

}

Solution

Animated gif's don't work well by default in JTable. But there is an easy way to fix this, use the AnimatedIcon class that can be found here

Basically, it reimplements Icon interface, register where you rendered the icon, and when a new frame of the gif needs to be painted, it will automatically repaint the correct area.

There is another alternative provided here where you register a specific ImageObserver for each cell that needs to render an animated gif, but I find it a bit more tedious.



Answered By - Guillaume Polet
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] how can I show loading gif until deleting?

 July 18, 2022     asp.net, c#, gif     No comments   

Issue

I have a delete button on a repeater which is in update panel. When i click the delete button, it can delete, but It takes about 10 seconds. So I want to add a loading gif . I am beginner on adding gif. Please help me. Thanks for interests

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:NET2ConnectionString %>' SelectCommand="SELECT * FROM [ProductsRA]"></asp:SqlDataSource>
                <asp:Repeater ID="rptuser" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="rpr1_ItemCommand" OnItemDataBound="rpr1_ItemDataBound">
                    <ItemTemplate>
                        <tr>
                            <td class="GridItems">
                                <asp:ImageButton runat="server" ID="delbtn" ImageUrl="~/images/delete.gif" CommandName="Delete" CommandArgument='<%# Eval("ID") %>' ValidationGroup="ab" ToolTip="Delete User" /></td>
                            <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"ID") %></td>
                            <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"ProductName") %></td>
                            <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"Quantity") %></td>
                            <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"UnitPrice") %></td>
                            <td class="GridItems">
                            </td>
                        </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                        </table>
                    </FooterTemplate>
                </asp:Repeater>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="rptuser" />
            </Triggers>
        </asp:UpdatePanel>

this is cs:

 protected void rpr1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    DataSet.ProductsRADataTable dt = new DataSet.ProductsRADataTable();
    DataSetTableAdapters.ProductsRATableAdapter adp = new DataSetTableAdapters.ProductsRATableAdapter();

    if (e.CommandName == "Delete")
    {
       adp.DeleteQuery(Convert.ToInt32(e.CommandArgument));
    }
}

Solution

You can use UpdateProgess control for this.

<asp:UpdateProgress ID="UpdateProgress1" runat="server"
        AssociatedUpdatePanelID="UpdatePanel1">
    <ProgressTemplate>
        <div class="loading_div">            
            <p>Please wait while we process the request.</p>
            <img src="/Images/loader.gif" />
        </div>
    </ProgressTemplate>
</asp:UpdateProgress>

Use an overlay div if you want to block the page while processing the request.

.loading_div {
    position: absolute;
    color:#fff;
    background-color: #000;
    z-index: 2000 !important;
    opacity: 0.6;
    overflow: hidden;
    text-align: center;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    padding-top:20%;
}

It will render like this while the request is processed: http://jsfiddle.net/codeandcloud/jLmbmLmn/



Answered By - naveen
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why does the GIF spec require at least 2-bits for the initial LZW code size?

 July 18, 2022     algorithm, gif     No comments   

Issue

I've been trying to figure out why the GIF89a spec requires that the initial LZW code size to be at least 2-bits, even when encoding 1-bit images (B&W). In appendix F of the spec, it says the following:

ESTABLISH CODE SIZE

The first byte of the Compressed Data stream is a value indicating the minimum number of bits required to represent the set of actual pixel values. Normally this will be the same as the number of color bits. Because of some algorithmic constraints however, black & white images which have one color bit must be indicated as having a code size of 2.

I'm curious as to what these algorithmic constraints are. What would possibly prevent the variant of LZW used in GIF from using a code size of 1? Was this just a limitation of the early encoders or decoders? Or is there some weird edge case that can manifest itself in with just the right combination of bits? Or is there something completely different going on here?


Solution

In addition to the codes for 0 and 1, you also have a clear code and an end of information code.

Quoting from the spec:

The output codes are of variable length, starting at +1 bits per code, up to 12 bits per code. This defines a maximum code value of 4095 (0xFFF). Whenever the LZW code value would exceed the current code length, the code length is increased by one.

If you start with a code size of 1, the code size needs to be increased immediately by this rule.



Answered By - Mark Ransom
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing